what.models.detection.yolo.yolov4_tiny

 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_tiny_anchors
11
12def mish(x):
13    return x * K.tanh(K.softplus(x))
14
15class YOLOV4_TINY:
16    def __init__(self, class_names, model_path):
17        self.model = load_model(model_path, custom_objects = {
18            'tf': tf,
19            'mish': mish
20        })
21        self.class_names = class_names
22        self.timer = Timer()
23
24    def predict(self, image, top_k=-1, prob_threshold=None):
25        input_cv_image = cv2.resize(image, (416, 416))
26        input_cv_image = np.array(input_cv_image).astype(np.float32) / 255.0
27
28        # Yolo inference
29        self.timer.start()
30        outs = self.model.predict(np.array([input_cv_image]))
31        print("FPS: ", int(1.0 / self.timer.end()))
32
33        boxes, class_ids, confidences = yolo_process_output(outs, yolov4_tiny_anchors, len(self.class_names))
34
35        return input_cv_image, boxes, class_ids, confidences
def mish(x):
13def mish(x):
14    return x * K.tanh(K.softplus(x))
class YOLOV4_TINY:
16class YOLOV4_TINY:
17    def __init__(self, class_names, model_path):
18        self.model = load_model(model_path, custom_objects = {
19            'tf': tf,
20            'mish': mish
21        })
22        self.class_names = class_names
23        self.timer = Timer()
24
25    def predict(self, image, top_k=-1, prob_threshold=None):
26        input_cv_image = cv2.resize(image, (416, 416))
27        input_cv_image = np.array(input_cv_image).astype(np.float32) / 255.0
28
29        # Yolo inference
30        self.timer.start()
31        outs = self.model.predict(np.array([input_cv_image]))
32        print("FPS: ", int(1.0 / self.timer.end()))
33
34        boxes, class_ids, confidences = yolo_process_output(outs, yolov4_tiny_anchors, len(self.class_names))
35
36        return input_cv_image, boxes, class_ids, confidences
YOLOV4_TINY(class_names, model_path)
17    def __init__(self, class_names, model_path):
18        self.model = load_model(model_path, custom_objects = {
19            'tf': tf,
20            'mish': mish
21        })
22        self.class_names = class_names
23        self.timer = Timer()
def predict(self, image, top_k=-1, prob_threshold=None):
25    def predict(self, image, top_k=-1, prob_threshold=None):
26        input_cv_image = cv2.resize(image, (416, 416))
27        input_cv_image = np.array(input_cv_image).astype(np.float32) / 255.0
28
29        # Yolo inference
30        self.timer.start()
31        outs = self.model.predict(np.array([input_cv_image]))
32        print("FPS: ", int(1.0 / self.timer.end()))
33
34        boxes, class_ids, confidences = yolo_process_output(outs, yolov4_tiny_anchors, len(self.class_names))
35
36        return input_cv_image, boxes, class_ids, confidences