what.models.detection.yolo.yolov3
1import cv2 2import numpy as np 3from keras.models import load_model 4 5from what.models.detection.utils.time_utils import Timer 6 7from .utils.yolo_utils import yolo_process_output, yolov3_anchors 8 9class YOLOV3: 10 def __init__(self, class_names, model_path): 11 self.model = load_model(model_path) 12 self.class_names = class_names 13 self.timer = Timer() 14 15 def predict(self, image, top_k=-1, prob_threshold=None): 16 input_cv_image = cv2.resize(image, (416, 416)) 17 input_cv_image = np.array(input_cv_image).astype(np.float32) / 255.0 18 19 # Yolo inference 20 self.timer.start() 21 outs = self.model.predict(np.array([input_cv_image])) 22 print("FPS: ", int(1.0 / self.timer.end())) 23 24 boxes, class_ids, confidences = yolo_process_output(outs, yolov3_anchors, len(self.class_names)) 25 26 return input_cv_image, boxes, class_ids, confidences
class
YOLOV3:
10class YOLOV3: 11 def __init__(self, class_names, model_path): 12 self.model = load_model(model_path) 13 self.class_names = class_names 14 self.timer = Timer() 15 16 def predict(self, image, top_k=-1, prob_threshold=None): 17 input_cv_image = cv2.resize(image, (416, 416)) 18 input_cv_image = np.array(input_cv_image).astype(np.float32) / 255.0 19 20 # Yolo inference 21 self.timer.start() 22 outs = self.model.predict(np.array([input_cv_image])) 23 print("FPS: ", int(1.0 / self.timer.end())) 24 25 boxes, class_ids, confidences = yolo_process_output(outs, yolov3_anchors, len(self.class_names)) 26 27 return input_cv_image, boxes, class_ids, confidences
def
predict(self, image, top_k=-1, prob_threshold=None):
16 def predict(self, image, top_k=-1, prob_threshold=None): 17 input_cv_image = cv2.resize(image, (416, 416)) 18 input_cv_image = np.array(input_cv_image).astype(np.float32) / 255.0 19 20 # Yolo inference 21 self.timer.start() 22 outs = self.model.predict(np.array([input_cv_image])) 23 print("FPS: ", int(1.0 / self.timer.end())) 24 25 boxes, class_ids, confidences = yolo_process_output(outs, yolov3_anchors, len(self.class_names)) 26 27 return input_cv_image, boxes, class_ids, confidences