def darknet53_tiny(input_data): input_data = common.convolutional(input_data, (3, 3, 3, 16)) input_data = tf.keras.layers.MaxPool2D(2, 2, 'same')(input_data) input_data = common.convolutional(input_data, (3, 3, 16, 32)) input_data = tf.keras.layers.MaxPool2D(2, 2, 'same')(input_data) input_data = common.convolutional(input_data, (3, 3, 32, 64)) input_data = tf.keras.layers.MaxPool2D(2, 2, 'same')(input_data) input_data = common.convolutional(input_data, (3, 3, 64, 128)) input_data = tf.keras.layers.MaxPool2D(2, 2, 'same')(input_data) input_data = common.convolutional(input_data, (3, 3, 128, 256)) route_1 = input_data input_data = tf.keras.layers.MaxPool2D(2, 2, 'same')(input_data) input_data = common.convolutional(input_data, (3, 3, 256, 512)) input_data = tf.keras.layers.MaxPool2D(2, 1, 'same')(input_data) input_data = common.convolutional(input_data, (3, 3, 512, 1024)) return route_1, input_data
def YOLOv3_tiny(input_layer, NUM_CLASS): route_1, conv = backbone.darknet53_tiny(input_layer) conv = common.convolutional(conv, (1, 1, 1024, 256)) conv_lobj_branch = common.convolutional(conv, (3, 3, 256, 512)) conv_lbbox = common.convolutional(conv_lobj_branch, (1, 1, 512, 3 * (NUM_CLASS + 5)), activate=False, bn=False) conv = common.convolutional(conv, (1, 1, 256, 128)) conv = common.upsample(conv) conv = tf.concat([conv, route_1], axis=-1) conv_mobj_branch = common.convolutional(conv, (3, 3, 128, 256)) conv_mbbox = common.convolutional(conv_mobj_branch, (1, 1, 256, 3 * (NUM_CLASS + 5)), activate=False, bn=False) return [conv_mbbox, conv_lbbox]
def darknet53(input_data): input_data = common.convolutional(input_data, (3, 3, 3, 32)) input_data = common.convolutional(input_data, (3, 3, 32, 64), downsample=True) for i in range(1): input_data = common.residual_block(input_data, 64, 32, 64) input_data = common.convolutional(input_data, (3, 3, 64, 128), downsample=True) for i in range(2): input_data = common.residual_block(input_data, 128, 64, 128) input_data = common.convolutional(input_data, (3, 3, 128, 256), downsample=True) for i in range(8): input_data = common.residual_block(input_data, 256, 128, 256) route_1 = input_data input_data = common.convolutional(input_data, (3, 3, 256, 512), downsample=True) for i in range(8): input_data = common.residual_block(input_data, 512, 256, 512) route_2 = input_data input_data = common.convolutional(input_data, (3, 3, 512, 1024), downsample=True) for i in range(4): input_data = common.residual_block(input_data, 1024, 512, 1024) return route_1, route_2, input_data
def cspdarknet53(input_data): input_data = common.convolutional(input_data, (3, 3, 3, 32), activate_type="mish") input_data = common.convolutional(input_data, (3, 3, 32, 64), downsample=True, activate_type="mish") route = input_data route = common.convolutional(route, (1, 1, 64, 64), activate_type="mish") input_data = common.convolutional(input_data, (1, 1, 64, 64), activate_type="mish") for i in range(1): input_data = common.residual_block(input_data, 64, 32, 64, activate_type="mish") input_data = common.convolutional(input_data, (1, 1, 64, 64), activate_type="mish") input_data = tf.concat([input_data, route], axis=-1) input_data = common.convolutional(input_data, (1, 1, 128, 64), activate_type="mish") input_data = common.convolutional(input_data, (3, 3, 64, 128), downsample=True, activate_type="mish") route = input_data route = common.convolutional(route, (1, 1, 128, 64), activate_type="mish") input_data = common.convolutional(input_data, (1, 1, 128, 64), activate_type="mish") for i in range(2): input_data = common.residual_block(input_data, 64, 64, 64, activate_type="mish") input_data = common.convolutional(input_data, (1, 1, 64, 64), activate_type="mish") input_data = tf.concat([input_data, route], axis=-1) input_data = common.convolutional(input_data, (1, 1, 128, 128), activate_type="mish") input_data = common.convolutional(input_data, (3, 3, 128, 256), downsample=True, activate_type="mish") route = input_data route = common.convolutional(route, (1, 1, 256, 128), activate_type="mish") input_data = common.convolutional(input_data, (1, 1, 256, 128), activate_type="mish") for i in range(8): input_data = common.residual_block(input_data, 128, 128, 128, activate_type="mish") input_data = common.convolutional(input_data, (1, 1, 128, 128), activate_type="mish") input_data = tf.concat([input_data, route], axis=-1) input_data = common.convolutional(input_data, (1, 1, 256, 256), activate_type="mish") route_1 = input_data input_data = common.convolutional(input_data, (3, 3, 256, 512), downsample=True, activate_type="mish") route = input_data route = common.convolutional(route, (1, 1, 512, 256), activate_type="mish") input_data = common.convolutional(input_data, (1, 1, 512, 256), activate_type="mish") for i in range(8): input_data = common.residual_block(input_data, 256, 256, 256, activate_type="mish") input_data = common.convolutional(input_data, (1, 1, 256, 256), activate_type="mish") input_data = tf.concat([input_data, route], axis=-1) input_data = common.convolutional(input_data, (1, 1, 512, 512), activate_type="mish") route_2 = input_data input_data = common.convolutional(input_data, (3, 3, 512, 1024), downsample=True, activate_type="mish") route = input_data route = common.convolutional(route, (1, 1, 1024, 512), activate_type="mish") input_data = common.convolutional(input_data, (1, 1, 1024, 512), activate_type="mish") for i in range(4): input_data = common.residual_block(input_data, 512, 512, 512, activate_type="mish") input_data = common.convolutional(input_data, (1, 1, 512, 512), activate_type="mish") input_data = tf.concat([input_data, route], axis=-1) input_data = common.convolutional(input_data, (1, 1, 1024, 1024), activate_type="mish") input_data = common.convolutional(input_data, (1, 1, 1024, 512)) input_data = common.convolutional(input_data, (3, 3, 512, 1024)) input_data = common.convolutional(input_data, (1, 1, 1024, 512)) input_data = tf.concat([ tf.nn.max_pool(input_data, ksize=13, padding='SAME', strides=1), tf.nn.max_pool(input_data, ksize=9, padding='SAME', strides=1), tf.nn.max_pool(input_data, ksize=5, padding='SAME', strides=1), input_data ], axis=-1) input_data = common.convolutional(input_data, (1, 1, 2048, 512)) input_data = common.convolutional(input_data, (3, 3, 512, 1024)) input_data = common.convolutional(input_data, (1, 1, 1024, 512)) return route_1, route_2, input_data
def cspdarknet53_tiny(input_data): input_data = common.convolutional(input_data, (3, 3, 3, 32), downsample=True) input_data = common.convolutional(input_data, (3, 3, 32, 64), downsample=True) input_data = common.convolutional(input_data, (3, 3, 64, 64)) route = input_data input_data = common.route_group(input_data, 2, 1) input_data = common.convolutional(input_data, (3, 3, 32, 32)) route_1 = input_data input_data = common.convolutional(input_data, (3, 3, 32, 32)) input_data = tf.concat([input_data, route_1], axis=-1) input_data = common.convolutional(input_data, (1, 1, 32, 64)) input_data = tf.concat([route, input_data], axis=-1) input_data = tf.keras.layers.MaxPool2D(2, 2, 'same')(input_data) input_data = common.convolutional(input_data, (3, 3, 64, 128)) route = input_data input_data = common.route_group(input_data, 2, 1) input_data = common.convolutional(input_data, (3, 3, 64, 64)) route_1 = input_data input_data = common.convolutional(input_data, (3, 3, 64, 64)) input_data = tf.concat([input_data, route_1], axis=-1) input_data = common.convolutional(input_data, (1, 1, 64, 128)) input_data = tf.concat([route, input_data], axis=-1) input_data = tf.keras.layers.MaxPool2D(2, 2, 'same')(input_data) input_data = common.convolutional(input_data, (3, 3, 128, 256)) route = input_data input_data = common.route_group(input_data, 2, 1) input_data = common.convolutional(input_data, (3, 3, 128, 128)) route_1 = input_data input_data = common.convolutional(input_data, (3, 3, 128, 128)) input_data = tf.concat([input_data, route_1], axis=-1) input_data = common.convolutional(input_data, (1, 1, 128, 256)) route_1 = input_data input_data = tf.concat([route, input_data], axis=-1) input_data = tf.keras.layers.MaxPool2D(2, 2, 'same')(input_data) input_data = common.convolutional(input_data, (3, 3, 512, 512)) return route_1, input_data
def YOLOv4(input_layer, NUM_CLASS): route_1, route_2, conv = backbone.cspdarknet53(input_layer) route = conv conv = common.convolutional(conv, (1, 1, 512, 256)) conv = common.upsample(conv) route_2 = common.convolutional(route_2, (1, 1, 512, 256)) conv = tf.concat([route_2, conv], axis=-1) conv = common.convolutional(conv, (1, 1, 512, 256)) conv = common.convolutional(conv, (3, 3, 256, 512)) conv = common.convolutional(conv, (1, 1, 512, 256)) conv = common.convolutional(conv, (3, 3, 256, 512)) conv = common.convolutional(conv, (1, 1, 512, 256)) route_2 = conv conv = common.convolutional(conv, (1, 1, 256, 128)) conv = common.upsample(conv) route_1 = common.convolutional(route_1, (1, 1, 256, 128)) conv = tf.concat([route_1, conv], axis=-1) conv = common.convolutional(conv, (1, 1, 256, 128)) conv = common.convolutional(conv, (3, 3, 128, 256)) conv = common.convolutional(conv, (1, 1, 256, 128)) conv = common.convolutional(conv, (3, 3, 128, 256)) conv = common.convolutional(conv, (1, 1, 256, 128)) route_1 = conv conv = common.convolutional(conv, (3, 3, 128, 256)) conv_sbbox = common.convolutional(conv, (1, 1, 256, 3 * (NUM_CLASS + 5)), activate=False, bn=False) conv = common.convolutional(route_1, (3, 3, 128, 256), downsample=True) conv = tf.concat([conv, route_2], axis=-1) conv = common.convolutional(conv, (1, 1, 512, 256)) conv = common.convolutional(conv, (3, 3, 256, 512)) conv = common.convolutional(conv, (1, 1, 512, 256)) conv = common.convolutional(conv, (3, 3, 256, 512)) conv = common.convolutional(conv, (1, 1, 512, 256)) route_2 = conv conv = common.convolutional(conv, (3, 3, 256, 512)) conv_mbbox = common.convolutional(conv, (1, 1, 512, 3 * (NUM_CLASS + 5)), activate=False, bn=False) conv = common.convolutional(route_2, (3, 3, 256, 512), downsample=True) conv = tf.concat([conv, route], axis=-1) conv = common.convolutional(conv, (1, 1, 1024, 512)) conv = common.convolutional(conv, (3, 3, 512, 1024)) conv = common.convolutional(conv, (1, 1, 1024, 512)) conv = common.convolutional(conv, (3, 3, 512, 1024)) conv = common.convolutional(conv, (1, 1, 1024, 512)) conv = common.convolutional(conv, (3, 3, 512, 1024)) conv_lbbox = common.convolutional(conv, (1, 1, 1024, 3 * (NUM_CLASS + 5)), activate=False, bn=False) return [conv_sbbox, conv_mbbox, conv_lbbox]