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]
def locaNet(input_layer): input_data = common.convolutional(input_layer, (3, 3, cfg.INPUT_CHANNEL, 8)) # 320x224x8 input_data = common.convolutional(input_data, (3, 3, 8, 16), downsample=True) # 160x112x16 input_data = common.convolutional(input_data, (3, 3, 16, 32), downsample=True) # 80x56x32 input_data = common.convolutional(input_data, (3, 3, 32, 64), downsample=True) # 40x28x64 route_1 = input_data input_data = common.convolutional(input_data, (3, 3, 64, 128), downsample=True) # 20x14x128 route_2 = input_data input_data = common.convolutional(input_data, (3, 3, 128, 256), downsample=True) # 10x7x256 conv = common.convolutional(input_data, (1, 1, 256, 128)) # 10x7x128 conv = common.upsample(conv) # 20x14x128 conv = tf.keras.layers.Concatenate(axis=-1)([conv, route_2]) # 20x14x256 conv = common.convolutional(conv, (1, 1, 256, 128)) # 20x14x128 conv = common.upsample(conv) # 40x28x128 conv = tf.keras.layers.Concatenate(axis=-1)([conv, route_1]) # 40x28x192 conv_point = common.convolutional(input_data, (1, 1, 192, 2+NUM_CLASS), activate=False, bn=False) # 40x28x(2 + NUM_CLASS) return conv_point
def YOLOv3(input_layer, NUM_CLASS): route_1, route_2, conv = backbone.darknet53(input_layer) 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_lobj_branch = common.convolutional(conv, (3, 3, 512, 1024)) conv_lbbox = common.convolutional(conv_lobj_branch, (1, 1, 1024, 3 * (NUM_CLASS + 5)), activate=False, bn=False) conv = common.convolutional(conv, (1, 1, 512, 256)) conv = common.upsample(conv) conv = tf.concat([conv, route_2], axis=-1) conv = common.convolutional(conv, (1, 1, 768, 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)) conv_mobj_branch = common.convolutional(conv, (3, 3, 256, 512)) conv_mbbox = common.convolutional(conv_mobj_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 = common.convolutional(conv, (1, 1, 384, 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)) conv_sobj_branch = common.convolutional(conv, (3, 3, 128, 256)) conv_sbbox = common.convolutional(conv_sobj_branch, (1, 1, 256, 3 * (NUM_CLASS + 5)), activate=False, bn=False) return [conv_sbbox, conv_mbbox, conv_lbbox]
def yolo3(input_layer): branch_1,branch_2,conv = backbone.backbone(input_layer) conv = common.conv(conv,(1,512)) conv = common.conv(conv,(3,1024)) conv = common.conv(conv,(1,512)) conv = common.conv(conv,(3,1024)) conv = common.conv(conv,(1,512)) conv_l_branch = common.conv(conv,(3,1024)) l_output = common.conv(conv_l_branch,(1,3 * (NUM_CLASS + 5)),activation = False,bn = False) conv = common.conv(conv,(1,256)) conv = common.upsample(conv,"resize") conv = tf.concat([conv,branch_2],axis = -1) conv = common.conv(conv,(1,256)) conv = common.conv(conv,(3,512)) conv = common.conv(conv,(1,256)) conv = common.conv(conv,(3,512)) conv = common.conv(conv,(1,256)) conv_m_branch = common.conv(conv,(3,512)) m_output = common.conv(conv_m_branch,(1,3 * (NUM_CLASS + 5)),activation = False,bn = False) conv = common.conv(conv,(1,128)) conv = common.upsample(conv,"resize") conv = tf.concat([conv,branch_1],axis = -1) conv = common.conv(conv,(1,128)) conv = common.conv(conv,(3,256)) conv = common.conv(conv,(1,128)) conv = common.conv(conv,(3,256)) conv = common.conv(conv,(1,128)) conv_s_branch = common.conv(conv,(3,256)) s_output = common.conv(conv_s_branch,(1,3 * (NUM_CLASS + 5)),activation = False,bn = False) return [s_output,m_output,l_output]