def yolo_body(inputs, num_anchors, num_classes):
    """Create YOLO_V2 model CNN body in Keras."""
    darknet = Model(inputs, darknet_body()(inputs))
    conv20 = compose(DarknetConv2D_BN_Leaky(1024, (3, 3)),
                     DarknetConv2D_BN_Leaky(1024, (3, 3)))(darknet.output)

    conv13 = darknet.layers[43].output
    conv21 = DarknetConv2D_BN_Leaky(64, (1, 1))(conv13)
    # TODO: Allow Keras Lambda to use func arguments for output_shape?
    conv21_reshaped = Lambda(space_to_depth_x2,
                             output_shape=space_to_depth_x2_output_shape,
                             name='space_to_depth')(conv21)

    x = concatenate([conv21_reshaped, conv20])
    x = DarknetConv2D_BN_Leaky(1024, (3, 3))(x)
    x = DarknetConv2D(num_anchors * (num_classes + 5), (1, 1))(x)
    return Model(inputs, x)
示例#2
0
def yolo_body(inputs, num_anchors, num_classes):
    darknet = Model(inputs, darknet_body()(inputs))
    conv20 = compose(
        DarknetConv2D_BN_Leaky(1024, (3, 3)),
        DarknetConv2D_BN_Leaky(1024, (3, 3))
    )(darknet.output)

    conv13 = darknet.layers[43].output
    conv21 = DarknetConv2D_BN_Leaky(64, (1, 1))(conv13)

    conv21_reshaped = Lambda(
        space_to_depth_x2,
        output_shape=space_to_depth_X2_output_shape,
        name='space_to_depth'
    )(conv21)

    x = concatenate([conv21_reshaped, conv20])
    x = DarknetConv2D_BN_Leaky(1024, (3, 3))(x)
    x = DarknetConv2D(num_anchors * (num_classes + 5), (1, 1))(x)

    return Model(inputs, x)
CROP_BOTTOM = int(30)

nb_train_samples = nr_train_samples
nb_validation_samples = nr_val_samples
batch_size = 8

if K.image_data_format() == 'channels_first':
    input_shape = (3, img_height, img_width)
else:
    input_shape = (img_height, img_width, 3)

inputs = Input(shape=input_shape)
x = Cropping2D(cropping=((CROP_TOP, CROP_BOTTOM), (0, 0)),
               input_shape=input_shape)(inputs)
x = GaussianNoise(0.5)(x)
x = DarknetConv2D_BN_Leaky(32, (3, 3))(x)
x = MaxPooling2D()(x)
x = DarknetConv2D_BN_Leaky(64, (3, 3))(x)
x = MaxPooling2D()(x)
x = bottleneck_block(128, 64)(x)
x = MaxPooling2D()(x)
x = bottleneck_block(256, 128)(x)
x = MaxPooling2D()(x)
x = bottleneck_x2_block(512, 256)(x)
x = MaxPooling2D()(x)
x = bottleneck_x2_block(1024, 512)(x)
x = DarknetConv2D(1000, (1, 1), activation='softmax')(x)
x = GlobalAveragePooling2D()(x)
x = Dense(3, activation='softmax')(x)
model = Model(inputs, x)