示例#1
0
def TinyYOLO_Siamese(input_shape=(3, 416, 416), num_classes=80, num_priors=5):
    """Tiny YOLO (v2) architecture

    # Arguments
        input_shape: Shape of the input image
        num_classes: Number of classes (excluding background)

    # References
        https://arxiv.org/abs/1612.08242
        https://arxiv.org/abs/1506.02640
    """
    K.set_image_dim_ordering('th')

    input_tensor_1 = Input(shape=input_shape)
    input_tensor_2 = Input(shape=input_shape)
    net_1 = {}
    net_2 = {}
    net_1 = create_base_network(input_tensor_1, net_1)
    net_2 = create_base_network(input_tensor_2, net_2, True)

    merge_nets = (concat())([net_1['relu7'], net_2['relu7']])
    conv = (YOLOConvolution2D(1024,
                              3,
                              3,
                              border_mode='same',
                              subsample=(1, 1),
                              epsilon=0.000001))(merge_nets)
    ReLU = (LeakyReLU(alpha=0.1))(conv)
    outNet = (Convolution2D(num_priors * (4 + num_classes + 1),
                            1,
                            1,
                            border_mode='same',
                            subsample=(1, 1)))(ReLU)
    model = Model([net_1['input'], net_2['input']], outNet)
    return model
示例#2
0
def TinyYOLO(input_shape=(3,416,416),num_classes=80,num_priors=5):
    """Tiny YOLO (v2) architecture

    # Arguments
        input_shape: Shape of the input image
        num_classes: Number of classes (excluding background)

    # References
        https://arxiv.org/abs/1612.08242
        https://arxiv.org/abs/1506.02640
    """
    K.set_image_dim_ordering('th')

    net={}
    input_tensor = Input(shape=input_shape)
    net['input'] = input_tensor
    net['conv1'] = (YOLOConvolution2D(16, 3, 3, border_mode='same',subsample=(1,1),
                                      epsilon=0.000001))(net['input'])
    net['relu1'] = (LeakyReLU(alpha=0.1))(net['conv1'])
    net['pool1'] = (MaxPooling2D(pool_size=(2, 2),padding='valid'))(net['relu1'])
    net['conv2'] = (YOLOConvolution2D(32, 3, 3, border_mode='same',subsample=(1,1),
                                      epsilon=0.000001))(net['pool1'])
    net['relu2'] = (LeakyReLU(alpha=0.1))(net['conv2'])
    net['pool2'] = (MaxPooling2D(pool_size=(2, 2),padding='valid'))(net['relu2'])
    net['conv3'] = (YOLOConvolution2D(64, 3, 3, border_mode='same',subsample=(1,1),
                                      epsilon=0.000001))(net['pool2'])
    net['relu3'] = (LeakyReLU(alpha=0.1))(net['conv3'])
    net['pool3'] = (MaxPooling2D(pool_size=(2, 2),padding='valid'))(net['relu3'])
    net['conv4'] = (YOLOConvolution2D(128, 3, 3, border_mode='same',subsample=(1,1),
                                      epsilon=0.000001))(net['pool3'])
    net['relu4'] = (LeakyReLU(alpha=0.1))(net['conv4'])
    net['pool4'] = (MaxPooling2D(pool_size=(2, 2),padding='valid'))(net['relu4'])
    net['conv5'] = (YOLOConvolution2D(256, 3, 3, border_mode='same',subsample=(1,1),
                                      epsilon=0.000001))(net['pool4'])
    net['relu5'] = (LeakyReLU(alpha=0.1))(net['conv5'])
    net['pool5'] = (MaxPooling2D(pool_size=(2, 2),padding='valid'))(net['relu5'])
    net['conv6'] = (YOLOConvolution2D(512, 3, 3, border_mode='same',subsample=(1,1),
                                      epsilon=0.000001))(net['pool5'])
    net['relu6'] = (LeakyReLU(alpha=0.1))(net['conv6'])
    net['pool6'] = (MaxPooling2D(pool_size=(2, 2),strides=(1,1),padding='same'))(net['relu6'])
    net['conv7'] = (YOLOConvolution2D(1024, 3, 3, border_mode='same',subsample=(1,1),
                                      epsilon=0.000001))(net['pool6'])
    net['relu7'] = (LeakyReLU(alpha=0.1))(net['conv7'])
    net['conv8'] = (YOLOConvolution2D(1024, 3, 3, border_mode='same',subsample=(1,1),
                                      epsilon=0.000001))(net['relu7'])
    net['relu8'] = (LeakyReLU(alpha=0.1))(net['conv8'])
    net['conv9'] = (Conv2D(num_priors*(4+num_classes+1), (1, 1), padding='same',
                                              strides=(1,1)))(net['relu8'])

    model = Model(net['input'], net['conv9'])
    return model
示例#3
0
def YOLO(input_shape=(3, 416, 416), num_classes=80, num_priors=5):
    """YOLO (v2) architecture

    # Arguments
        input_shape: Shape of the input image
        num_classes: Number of classes (excluding background)

    # References
        https://arxiv.org/abs/1612.08242
        https://arxiv.org/abs/1506.02640
    """
    K.set_image_dim_ordering('th')

    net = {}
    input_tensor = Input(shape=input_shape)
    net['input'] = input_tensor
    net['conv1'] = (YOLOConvolution2D(32,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['input'])
    net['relu1'] = (LeakyReLU(alpha=0.1))(net['conv1'])
    net['pool1'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu1'])
    net['conv2'] = (YOLOConvolution2D(64,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool1'])
    net['relu2'] = (LeakyReLU(alpha=0.1))(net['conv2'])
    net['pool2'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu2'])
    net['conv3_1'] = (YOLOConvolution2D(128,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['pool2'])
    net['relu3_1'] = (LeakyReLU(alpha=0.1))(net['conv3_1'])
    net['conv3_2'] = (YOLOConvolution2D(64,
                                        1,
                                        1,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu3_1'])
    net['relu3_2'] = (LeakyReLU(alpha=0.1))(net['conv3_2'])
    net['conv3_3'] = (YOLOConvolution2D(128,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu3_2'])
    net['relu3_3'] = (LeakyReLU(alpha=0.1))(net['conv3_3'])
    net['pool3'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu3_3'])
    net['conv4_1'] = (YOLOConvolution2D(256,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['pool3'])
    net['relu4_1'] = (LeakyReLU(alpha=0.1))(net['conv4_1'])
    net['conv4_2'] = (YOLOConvolution2D(128,
                                        1,
                                        1,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu4_1'])
    net['relu4_2'] = (LeakyReLU(alpha=0.1))(net['conv4_2'])
    net['conv4_3'] = (YOLOConvolution2D(256,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu4_2'])
    net['relu4_3'] = (LeakyReLU(alpha=0.1))(net['conv4_3'])
    net['pool4'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu4_3'])
    net['conv5_1'] = (YOLOConvolution2D(512,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['pool4'])
    net['relu5_1'] = (LeakyReLU(alpha=0.1))(net['conv5_1'])
    net['conv5_2'] = (YOLOConvolution2D(256,
                                        1,
                                        1,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu5_1'])
    net['relu5_2'] = (LeakyReLU(alpha=0.1))(net['conv5_2'])
    net['conv5_3'] = (YOLOConvolution2D(512,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu5_2'])
    net['relu5_3'] = (LeakyReLU(alpha=0.1))(net['conv5_3'])
    net['conv5_4'] = (YOLOConvolution2D(256,
                                        1,
                                        1,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu5_3'])
    net['relu5_4'] = (LeakyReLU(alpha=0.1))(net['conv5_4'])
    net['conv5_5'] = (YOLOConvolution2D(512,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu5_4'])
    net['relu5_5'] = (LeakyReLU(alpha=0.1))(net['conv5_5'])
    net['pool5'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu5_5'])
    net['conv6_1'] = (YOLOConvolution2D(1024,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['pool5'])
    net['relu6_1'] = (LeakyReLU(alpha=0.1))(net['conv6_1'])
    net['conv6_2'] = (YOLOConvolution2D(512,
                                        1,
                                        1,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_1'])
    net['relu6_2'] = (LeakyReLU(alpha=0.1))(net['conv6_2'])
    net['conv6_3'] = (YOLOConvolution2D(1024,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_2'])
    net['relu6_3'] = (LeakyReLU(alpha=0.1))(net['conv6_3'])
    net['conv6_4'] = (YOLOConvolution2D(512,
                                        1,
                                        1,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_3'])
    net['relu6_4'] = (LeakyReLU(alpha=0.1))(net['conv6_4'])
    net['conv6_5'] = (YOLOConvolution2D(1024,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_4'])
    net['relu6_5'] = (LeakyReLU(alpha=0.1))(net['conv6_5'])
    net['conv6_6'] = (YOLOConvolution2D(1024,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_5'])
    net['relu6_6'] = (LeakyReLU(alpha=0.1))(net['conv6_6'])
    net['conv6_7'] = (YOLOConvolution2D(1024,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_6'])
    net['relu6_7'] = (LeakyReLU(alpha=0.1))(net['conv6_7'])
    net['reorg7'] = (Reorg())(net['relu5_5'])
    net['merge7'] = (merge([net['reorg7'], net['relu6_7']],
                           mode='concat',
                           concat_axis=1))
    net['conv8'] = (YOLOConvolution2D(1024,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['merge7'])
    net['relu8'] = (LeakyReLU(alpha=0.1))(net['conv8'])
    net['conv9'] = (Convolution2D(num_priors * (4 + num_classes + 1),
                                  1,
                                  1,
                                  border_mode='same',
                                  subsample=(1, 1)))(net['relu8'])

    model = Model(net['input'], net['conv9'])
    return model
示例#4
0
def TinyYOLT(input_shape=(3, 416, 416), num_classes=80, num_priors=5):
    """Tiny TinyYOLT architecture

    # Arguments
        input_shape: Shape of the input image
        num_classes: Number of classes (excluding background)

    # References
        https://arxiv.org/abs/1612.08242
        https://arxiv.org/abs/1506.02640
    """
    K.set_image_dim_ordering('th')

    input_tensor = Input(shape=input_shape)
    net = {}
    net['input'] = input_tensor

    # Scale 1
    net['input_scale1'] = (YOLOConvolution2D(16,
                                             3,
                                             3,
                                             border_mode='same',
                                             subsample=(1, 1),
                                             epsilon=0.000001))(net['input'])

    # Scale 2
    net['deconv'] = Deconvolution2D(3,
                                    4,
                                    4,
                                    net['input']._keras_shape,
                                    'glorot_uniform',
                                    'linear',
                                    border_mode='valid',
                                    subsample=(2, 2),
                                    name='deconv')(net['input'])
    net['deconv'] = UpSampling2D(size=(2, 2))((net['input']))

    net['conv1'] = (YOLOConvolution2D(16,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['deconv'])

    net['input_scale2'] = (MaxPooling2D(pool_size=(2, 2),
                                        border_mode='valid'))(net['conv1'])

    # Merge scales
    # net['merge'] = (concat())([net['input_scale1'], net['input_scale2']])
    net['merge'] = merge([net['input_scale1'], net['input_scale2']],
                         mode='concat',
                         name='merge',
                         concat_axis=1)

    net['relu1'] = (LeakyReLU(alpha=0.1))(net['merge'])
    net['pool1'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu1'])
    net['conv2'] = (YOLOConvolution2D(32,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool1'])

    net['relu2'] = (LeakyReLU(alpha=0.1))(net['conv2'])
    net['pool2'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu2'])
    net['conv3'] = (YOLOConvolution2D(64,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool2'])
    net['relu3'] = (LeakyReLU(alpha=0.1))(net['conv3'])
    net['pool3'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu3'])
    net['conv4'] = (YOLOConvolution2D(128,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool3'])
    net['relu4'] = (LeakyReLU(alpha=0.1))(net['conv4'])
    net['pool4'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu4'])
    net['conv5'] = (YOLOConvolution2D(256,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool4'])
    net['relu5'] = (LeakyReLU(alpha=0.1))(net['conv5'])
    net['pool5'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu5'])
    net['conv6'] = (YOLOConvolution2D(512,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool5'])
    net['relu6'] = (LeakyReLU(alpha=0.1))(net['conv6'])
    net['pool6'] = (MaxPooling2D(pool_size=(2, 2),
                                 strides=(1, 1),
                                 border_mode='same'))(net['relu6'])
    net['conv7'] = (YOLOConvolution2D(1024,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool6'])
    net['relu7'] = (LeakyReLU(alpha=0.1))(net['conv7'])
    net['conv8'] = (YOLOConvolution2D(1024,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['relu7'])
    net['relu8'] = (LeakyReLU(alpha=0.1))(net['conv8'])
    net['output'] = (Convolution2D(num_priors * (4 + num_classes + 1),
                                   1,
                                   1,
                                   border_mode='same',
                                   subsample=(1, 1)))(net['relu8'])
    model = Model(net['input'], net['output'])
    return model
示例#5
0
def create_base_network(input_dim, net, doubleScaling=False):

    net['input'] = input_dim

    if doubleScaling:

        output_shape_tensor = getShapeLayer(net['input'])

        net['deconv'] = (YOLODeconvolution2D(3,
                                             3,
                                             3,
                                             batch_size=16,
                                             border_mode='same',
                                             subsample=(1, 1),
                                             epsilon=0.000001))(net['input'])

        net['conv1'] = (YOLOConvolution2D(16,
                                          3,
                                          3,
                                          border_mode='same',
                                          subsample=(1, 1),
                                          epsilon=0.000001))(net['deconv'])
        net['input1'] = (MaxPooling2D(pool_size=(2, 2),
                                      border_mode='valid'))(net['conv1'])

    else:
        net['input1'] = (YOLOConvolution2D(16,
                                           3,
                                           3,
                                           border_mode='same',
                                           subsample=(1, 1),
                                           epsilon=0.000001))(net['input'])

    net['relu1'] = (LeakyReLU(alpha=0.1))(net['input1'])
    net['pool1'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu1'])
    net['conv2'] = (YOLOConvolution2D(32,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool1'])

    net['relu2'] = (LeakyReLU(alpha=0.1))(net['conv2'])
    net['pool2'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu2'])
    net['conv3'] = (YOLOConvolution2D(64,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool2'])
    net['relu3'] = (LeakyReLU(alpha=0.1))(net['conv3'])
    net['pool3'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu3'])
    net['conv4'] = (YOLOConvolution2D(128,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool3'])
    net['relu4'] = (LeakyReLU(alpha=0.1))(net['conv4'])
    net['pool4'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu4'])
    net['conv5'] = (YOLOConvolution2D(256,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool4'])
    net['relu5'] = (LeakyReLU(alpha=0.1))(net['conv5'])
    net['pool5'] = (MaxPooling2D(pool_size=(2, 2),
                                 border_mode='valid'))(net['relu5'])
    net['conv6'] = (YOLOConvolution2D(512,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool5'])
    net['relu6'] = (LeakyReLU(alpha=0.1))(net['conv6'])
    net['pool6'] = (MaxPooling2D(pool_size=(2, 2),
                                 strides=(1, 1),
                                 border_mode='same'))(net['relu6'])
    net['conv7'] = (YOLOConvolution2D(1024,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['pool6'])
    net['relu7'] = (LeakyReLU(alpha=0.1))(net['conv7'])

    return net
示例#6
0
def vgg16YOLO(input_shape=(3, 416, 416), num_classes=80, num_priors=5):
    """YOLO (v2) architecture

    # Arguments
        input_shape: Shape of the input image
        num_classes: Number of classes (excluding background)

    # References
        https://arxiv.org/abs/1612.08242
        https://arxiv.org/abs/1506.02640
    """
    K.set_image_dim_ordering('th')

    net = {}
    # Block 1
    input_tensor = input_tensor = Input(shape=input_shape)
    img_size = (input_shape[1], input_shape[0])
    net['input'] = input_tensor
    net['conv1_1'] = Convolution2D(64,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv1_1')(net['input'])
    net['conv1_2'] = Convolution2D(64,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv1_2')(net['conv1_1'])
    net['pool1'] = MaxPooling2D((2, 2),
                                strides=(2, 2),
                                border_mode='same',
                                name='pool1')(net['conv1_2'])
    # Block 2
    net['conv2_1'] = Convolution2D(128,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv2_1')(net['pool1'])
    net['conv2_2'] = Convolution2D(128,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv2_2')(net['conv2_1'])
    net['pool2'] = MaxPooling2D((2, 2),
                                strides=(2, 2),
                                border_mode='same',
                                name='pool2')(net['conv2_2'])
    # Block 3
    net['conv3_1'] = Convolution2D(256,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv3_1')(net['pool2'])
    net['conv3_2'] = Convolution2D(256,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv3_2')(net['conv3_1'])
    net['conv3_3'] = Convolution2D(256,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv3_3')(net['conv3_2'])
    net['pool3'] = MaxPooling2D((2, 2),
                                strides=(2, 2),
                                border_mode='same',
                                name='pool3')(net['conv3_3'])
    # Block 4
    net['conv4_1'] = Convolution2D(512,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv4_1')(net['pool3'])
    net['conv4_2'] = Convolution2D(512,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv4_2')(net['conv4_1'])
    net['conv4_3'] = Convolution2D(512,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv4_3')(net['conv4_2'])
    net['pool4'] = MaxPooling2D((2, 2),
                                strides=(2, 2),
                                border_mode='same',
                                name='pool4')(net['conv4_3'])
    # Block 5
    net['conv5_1'] = Convolution2D(512,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv5_1')(net['pool4'])
    net['conv5_2'] = Convolution2D(512,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv5_2')(net['conv5_1'])
    net['conv5_3'] = Convolution2D(512,
                                   3,
                                   3,
                                   activation='relu',
                                   border_mode='same',
                                   name='conv5_3')(net['conv5_2'])
    # before are from VGG, below are from YOLO
    net['relu5_5'] = (LeakyReLU(alpha=0.1))(net['conv5_3'])
    net['pool5'] = (MaxPooling2D(pool_size=(2, 2),
                                 padding='valid'))(net['relu5_5'])

    net['conv6_1'] = (YOLOConvolution2D(1024,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['pool5'])
    net['relu6_1'] = (LeakyReLU(alpha=0.1))(net['conv6_1'])
    net['conv6_2'] = (YOLOConvolution2D(512,
                                        1,
                                        1,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_1'])
    net['relu6_2'] = (LeakyReLU(alpha=0.1))(net['conv6_2'])
    net['conv6_3'] = (YOLOConvolution2D(1024,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_2'])
    net['relu6_3'] = (LeakyReLU(alpha=0.1))(net['conv6_3'])
    net['conv6_4'] = (YOLOConvolution2D(512,
                                        1,
                                        1,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_3'])
    net['relu6_4'] = (LeakyReLU(alpha=0.1))(net['conv6_4'])
    net['conv6_5'] = (YOLOConvolution2D(1024,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_4'])
    net['relu6_5'] = (LeakyReLU(alpha=0.1))(net['conv6_5'])
    net['conv6_6'] = (YOLOConvolution2D(1024,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_5'])
    net['relu6_6'] = (LeakyReLU(alpha=0.1))(net['conv6_6'])
    net['conv6_7'] = (YOLOConvolution2D(1024,
                                        3,
                                        3,
                                        border_mode='same',
                                        subsample=(1, 1),
                                        epsilon=0.000001))(net['relu6_6'])
    net['relu6_7'] = (LeakyReLU(alpha=0.1))(net['conv6_7'])
    net['reorg7'] = (Reorg())(net['relu5_5'])
    net['merge7'] = (Concatenate(axis=1)([net['reorg7'], net['relu6_7']]))
    net['conv8'] = (YOLOConvolution2D(1024,
                                      3,
                                      3,
                                      border_mode='same',
                                      subsample=(1, 1),
                                      epsilon=0.000001))(net['merge7'])
    net['relu8'] = (LeakyReLU(alpha=0.1))(net['conv8'])
    net['conv9'] = (Conv2D(num_priors * (4 + num_classes + 1), (1, 1),
                           padding='same',
                           strides=(1, 1)))(net['relu8'])

    model = Model(net['input'], net['conv9'])
    return model
示例#7
0
def build_own_det(img_shape=(3, 224, 224), n_classes=1000, num_priors=5):
    K.set_image_dim_ordering('th')

    img_input = Input(shape=img_shape)
    # Steem
    x = Convolution2D(64, 7, 7, border_mode='same', subsample=(1,1), name='block1_conv1', activation='relu')(img_input)

    x = MaxPooling2D(pool_size=(3, 3), strides=(4, 4), padding='same', name='MaxPool_1')(x)
    x = BatchNormalization(name='Batch_1')(x)

    x = Convolution2D(64, 1, 1, border_mode='same', subsample=(1,1), name='block2_conv1', activation='relu')(x)

    x = Convolution2D(256, 3, 3, border_mode='same', subsample=(1,1), name='block2_conv2', activation='relu')(x)

    x = BatchNormalization(name='Batch_2')(x)

    steem_output = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), padding='same', name='steem_output')(x)

    # Inception 1
    inc_1_1 = Convolution2D(64, 1, 1, border_mode='same', subsample=(1,1), name='inc_1_1', activation='relu')(steem_output)

    inc_1_2_a = Convolution2D(96, 1, 1, border_mode='same', subsample=(1,1), name='inc_1_2_a', activation='relu')(steem_output)
    inc_1_2_b = Convolution2D(128, 3, 3, border_mode='same', subsample=(1,1), name='inc_1_2_b', activation='relu')(inc_1_2_a)

    inc_1_3_a = Convolution2D(16, 1, 1, border_mode='same', subsample=(1,1), name='inc_1_3_a', activation='relu')(steem_output)
    inc_1_3_b = Convolution2D(32, 5, 5, border_mode='same', subsample=(1,1), name='inc_1_3_b', activation='relu')(inc_1_3_a)

    inc_1_4_a = MaxPooling2D(pool_size=(3, 3), strides=(1, 1), padding='same', name='inc_1_4_a')(steem_output)
    inc_1_4_b = Convolution2D(32, 1, 1, border_mode='same', subsample=(1,1), name='inc_1_4_b', activation='relu')(inc_1_4_a)

    out_inc_1 = merge([inc_1_1, inc_1_2_b, inc_1_3_b, inc_1_4_b], mode='concat', concat_axis=1, name='out_inc_1')

    # Residual 1
    add_r1 = Add(name='add_r1')([steem_output, out_inc_1])
    add_1 = Convolution2D(480, 1, 1, border_mode='same', subsample=(1,1), name='add_1', activation='relu')(add_r1)

    # Inception 2
    inc_2_1 = Convolution2D(128, 1, 1, border_mode='same', subsample=(1,1), name='inc_2_1', activation='relu')(add_1)

    inc_2_2_a = Convolution2D(128, 1, 1, border_mode='same', subsample=(1,1), name='inc_2_2_a', activation='relu')(add_1)
    inc_2_2_b = Convolution2D(192, 3, 3, border_mode='same', subsample=(1,1), name='inc_2_2_b', activation='relu')(inc_2_2_a)

    inc_2_3_a = Convolution2D(32, 1, 1, border_mode='same', subsample=(1,1), name='inc_2_3_a', activation='relu')(add_1)
    inc_2_3_b = Convolution2D(96, 5, 5, border_mode='same', subsample=(1,1), name='inc_2_3_b', activation='relu')(inc_2_3_a)

    inc_2_4_a = MaxPooling2D(pool_size=(3, 3), strides=(1, 1), border_mode='same', name='inc_2_4_a')(add_1)
    inc_2_4_b = Convolution2D(64, 1, 1, border_mode='same', subsample=(1,1), name='inc_2_4_b', activation='relu')(inc_2_4_a)

    out_inc_2 = merge([inc_2_1, inc_2_2_b, inc_2_3_b, inc_2_4_b], mode='concat', concat_axis=1, name='out_inc_2')

    # Residual 2
    add_2 = Add(name='add_2')([add_1, out_inc_2])

    # Parallel block
    out_inc = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), padding='same', name='out_inc')(add_2)
    conv_3 = YOLOConvolution2D(512, 3, 3, border_mode='same', subsample=(1,1), name='block3_conv1')(out_inc)
    conv_3 = LeakyReLU(alpha=0.1)(conv_3)

    conv_4 = YOLOConvolution2D(1024, 3, 3, border_mode='same', subsample=(1,1), name='block4_conv1')(conv_3)
    conv_4 = LeakyReLU(alpha=0.1)(conv_4)

    conv_5 = YOLOConvolution2D(512, 3, 3, border_mode='same', subsample=(1,1), name='block5_conv1')(conv_4)
    conv_5 = LeakyReLU(alpha=0.1)(conv_5)

    conv_6 = YOLOConvolution2D(1024, 3, 3, border_mode='same', subsample=(1,1), name='block6_conv1')(conv_5)
    conv_6 = LeakyReLU(alpha=0.1)(conv_6)

    conv_7 = YOLOConvolution2D(512, 3, 3, border_mode='same', subsample=(1,1), name='block7_conv1')(conv_6)
    conv_7 = LeakyReLU(alpha=0.1)(conv_7)

    conv_8 = YOLOConvolution2D(1024, 3, 3, border_mode='same', subsample=(1,1), name='block8_conv1')(conv_7)
    conv_8 = LeakyReLU(alpha=0.1)(conv_8)

    reorg = (Reorg())(add_2)

    concat = Concatenate(axis=1)([conv_8, reorg])

    conv_9 = Convolution2D(1024, 3, 3, border_mode='same', subsample=(1,1), name='block9_conv1', activation='relu')(concat)

    last_conv = Convolution2D(num_priors * (4 + n_classes + 1), (1, 1), padding='same', strides=(1, 1), activation='relu')(conv_9)

    model = Model(input=img_input, output=last_conv)
    plot(model, to_file='team7_model_det.png', show_shapes=True, show_layer_names=True)

    return model