what.models.detection.yolo.yolov4
1import cv2 2import numpy as np 3 4import tensorflow as tf 5from keras.models import load_model 6import tensorflow.keras.backend as K 7 8from what.models.detection.utils.time_utils import Timer 9 10from .utils.yolo_utils import yolo_process_output, yolov4_anchors 11 12class YOLOV4: 13 def __init__(self, class_names, model_path): 14 self.model = load_model(model_path, custom_objects = { 15 'mish': lambda x: x * K.tanh(K.softplus(x)), 16 'tf': tf 17 }) 18 self.class_names = class_names 19 self.timer = Timer() 20 21 def predict(self, image, top_k=-1, prob_threshold=None): 22 input_cv_image = cv2.resize(image, (416, 416)) 23 input_cv_image = np.array(input_cv_image).astype(np.float32) / 255.0 24 25 # Yolo inference 26 self.timer.start() 27 outs = self.model.predict(np.array([input_cv_image])) 28 print("FPS: ", int(1.0 / self.timer.end())) 29 30 boxes, class_ids, confidences = yolo_process_output(outs, yolov4_anchors, len(self.class_names)) 31 32 return input_cv_image, boxes, class_ids, confidences
class
YOLOV4:
13class YOLOV4: 14 def __init__(self, class_names, model_path): 15 self.model = load_model(model_path, custom_objects = { 16 'mish': lambda x: x * K.tanh(K.softplus(x)), 17 'tf': tf 18 }) 19 self.class_names = class_names 20 self.timer = Timer() 21 22 def predict(self, image, top_k=-1, prob_threshold=None): 23 input_cv_image = cv2.resize(image, (416, 416)) 24 input_cv_image = np.array(input_cv_image).astype(np.float32) / 255.0 25 26 # Yolo inference 27 self.timer.start() 28 outs = self.model.predict(np.array([input_cv_image])) 29 print("FPS: ", int(1.0 / self.timer.end())) 30 31 boxes, class_ids, confidences = yolo_process_output(outs, yolov4_anchors, len(self.class_names)) 32 33 return input_cv_image, boxes, class_ids, confidences
def
predict(self, image, top_k=-1, prob_threshold=None):
22 def predict(self, image, top_k=-1, prob_threshold=None): 23 input_cv_image = cv2.resize(image, (416, 416)) 24 input_cv_image = np.array(input_cv_image).astype(np.float32) / 255.0 25 26 # Yolo inference 27 self.timer.start() 28 outs = self.model.predict(np.array([input_cv_image])) 29 print("FPS: ", int(1.0 / self.timer.end())) 30 31 boxes, class_ids, confidences = yolo_process_output(outs, yolov4_anchors, len(self.class_names)) 32 33 return input_cv_image, boxes, class_ids, confidences