<jupyter_start><jupyter_text>YOLO Network (small version) Constructor<jupyter_code>def YOLO_small(leaky_alpha=0.1):
    model = Sequential()
    
    model.add(ZeroPadding2D(3, input_shape=(448, 448, 3)))
    model.add(Conv2D(64, 7, 2, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(MaxPooling2D(2, 2, padding='same'))
    
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(192, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(MaxPooling2D(2, 2, padding='same'))
    
    model.add(Conv2D(128, 1, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(256, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(Conv2D(256, 1, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(512, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(MaxPooling2D(2, 2, padding='same'))
    
    model.add(Conv2D(256, 1, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(512, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(Conv2D(256, 1, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(512, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(Conv2D(256, 1, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(512, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(Conv2D(256, 1, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(512, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(Conv2D(512, 1, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(1024 ,3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(MaxPooling2D(2, 2, padding='same'))
    
    model.add(Conv2D(512, 1, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(1024, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(Conv2D(512, 1, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(1024, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(1024, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(1024, 3, 2, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(1024, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(ZeroPadding2D(1))
    model.add(Conv2D(1024, 3, 1, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    
    model.add(Flatten())
    model.add(Dense(512, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(Dense(4096, use_bias=True))
    model.add(LeakyReLU(leaky_alpha))
    model.add(Dense(1470, use_bias=True))
    
    model.summary()
    return model<jupyter_output><empty_output><jupyter_text>Define Detector<jupyter_code>class YOLODetector():
    def __init__(self, model):
        self.model = model
    
    def detect(self, img):
        h_img, w_img, _ = img.shape
        img_resized = cv2.resize(img, (448, 448))
        img_RGB = cv2.cvtColor(img_resized, cv2.COLOR_BGR2RGB)
        img_resized_np = np.asarray(img_RGB)
        inputs = np.zeros((1, 448, 448, 3), dtype='float32')
        inputs[0] = (img_resized_np/255.0)*2.0-1.0
        outputs = self.model.predict(inputs)
        result = interpret_output(outputs[0], w_img, h_img, threshold=0.2, iou_threshold=0.5)
        return result
model = YOLO_small()
model.load_weights('YOLO_small.h5')
yolo_detector = YOLODetector(model)
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (16, 9)
img = cv2.imread('test.jpg')
result = yolo_detector.detect(img)
result_img = draw_result(img, result)
plt.imshow(result_img)
plt.show()<jupyter_output><empty_output><jupyter_text>Run Server<jupyter_code>serve(Detector(yolo_detector))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15293296089385475, 'fraction_numerical': 0.05842644320297952, 'mean_word_length': 4.494884910485934, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '407003', 'license': 'MIT', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1789, 'n_words': 232, 'path': 'Real-Time Object Detection.ipynb', 'repo_name': 'xdshang/real-time-object-detection', 'size': '4296'}