Created
June 4, 2020 14:01
-
-
Save pythonlessons/f9553871deee32ded66ab4a41fe09327 to your computer and use it in GitHub Desktop.
Yolo_v3_tiny_structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def darknet19_tiny(input_data): | |
| input_data = convolutional(input_data, (3, 3, 3, 16)) | |
| input_data = MaxPool2D(2, 2, 'same')(input_data) | |
| input_data = convolutional(input_data, (3, 3, 16, 32)) | |
| input_data = MaxPool2D(2, 2, 'same')(input_data) | |
| input_data = convolutional(input_data, (3, 3, 32, 64)) | |
| input_data = MaxPool2D(2, 2, 'same')(input_data) | |
| input_data = convolutional(input_data, (3, 3, 64, 128)) | |
| input_data = MaxPool2D(2, 2, 'same')(input_data) | |
| input_data = convolutional(input_data, (3, 3, 128, 256)) | |
| route_1 = input_data | |
| input_data = MaxPool2D(2, 2, 'same')(input_data) | |
| input_data = convolutional(input_data, (3, 3, 256, 512)) | |
| input_data = MaxPool2D(2, 1, 'same')(input_data) | |
| input_data = convolutional(input_data, (3, 3, 512, 1024)) | |
| return route_1, input_data | |
| def YOLOv3_tiny(input_layer, NUM_CLASS): | |
| # After the input layer enters the Darknet-53 network, we get three branches | |
| route_1, conv = darknet19_tiny(input_layer) | |
| conv = convolutional(conv, (1, 1, 1024, 256)) | |
| conv_lobj_branch = convolutional(conv, (3, 3, 256, 512)) | |
| # conv_lbbox is used to predict large-sized objects , Shape = [None, 26, 26, 255] | |
| conv_lbbox = convolutional(conv_lobj_branch, (1, 1, 512, 3*(NUM_CLASS + 5)), activate=False, bn=False) | |
| conv = convolutional(conv, (1, 1, 256, 128)) | |
| # upsample here uses the nearest neighbor interpolation method, which has the advantage that the | |
| # upsampling process does not need to learn, thereby reducing the network parameter | |
| conv = upsample(conv) | |
| conv = tf.concat([conv, route_1], axis=-1) | |
| conv_mobj_branch = convolutional(conv, (3, 3, 128, 256)) | |
| # conv_mbbox is used to predict medium size objects, shape = [None, 13, 13, 255] | |
| conv_mbbox = convolutional(conv_mobj_branch, (1, 1, 256, 3 * (NUM_CLASS + 5)), activate=False, bn=False) | |
| return [conv_mbbox, conv_lbbox] | |
| def Create_Yolov3(input_size=416, channels=3, training=False, CLASSES=YOLO_COCO_CLASSES): | |
| NUM_CLASS = len(read_class_names(CLASSES)) | |
| input_layer = Input([input_size, input_size, channels]) | |
| if TRAIN_YOLO_TINY: | |
| conv_tensors = YOLOv3_tiny(input_layer, NUM_CLASS) | |
| else: | |
| conv_tensors = YOLOv3(input_layer, NUM_CLASS) | |
| output_tensors = [] | |
| for i, conv_tensor in enumerate(conv_tensors): | |
| pred_tensor = decode(conv_tensor, NUM_CLASS, i) | |
| if training: output_tensors.append(conv_tensor) | |
| output_tensors.append(pred_tensor) | |
| YoloV3 = tf.keras.Model(input_layer, output_tensors) | |
| return YoloV3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment