def my_assessor_model(mouth_nn='cnn', mouth_features_dim=512, lstm_units_1=32, dense_fc_1=128, dense_fc_2=64,
                      conv_f_1=32, conv_f_2=64, conv_f_3=128, dropout_p=0.2):

    mouth_input_shape = (MOUTH_H, MOUTH_W, MOUTH_CHANNELS)
    my_input_mouth_images = Input(shape=(TIME_STEPS, *mouth_input_shape))
    my_input_head_poses = Input(shape=(TIME_STEPS, 3))
    my_input_n_of_frames = Input(shape=(1,))
    my_input_lipreader_dense = Input(shape=(1024,))
    my_input_lipreader_softmax = Input(shape=(500,))

    if mouth_nn == 'cnn':
        mouth_feature_model = my_timedistributed_cnn_model((TIME_STEPS, *mouth_input_shape), conv_f_1, conv_f_2, conv_f_3, mouth_features_dim)
    elif mouth_nn == 'resnet18':
        mouth_feature_model = ResnetBuilder.build_resnet_18((TIME_STEPS, *mouth_input_shape), mouth_features_dim, time_distributed=True)
    elif mouth_nn == 'resnet34':
        mouth_feature_model = ResnetBuilder.build_resnet_34((TIME_STEPS, *mouth_input_shape), mouth_features_dim, time_distributed=True)
    elif mouth_nn == 'resnet50':
        mouth_feature_model = ResnetBuilder.build_resnet_50((TIME_STEPS, *mouth_input_shape), mouth_features_dim, time_distributed=True)
    elif mouth_nn == 'resnet101':
        mouth_feature_model = ResnetBuilder.build_resnet_101((TIME_STEPS, *mouth_input_shape), mouth_features_dim, time_distributed=True)
    elif mouth_nn == 'resnet152':
        mouth_feature_model = ResnetBuilder.build_resnet_152((TIME_STEPS, *mouth_input_shape), mouth_features_dim, time_distributed=True)
    elif mouth_nn == 'flatten':
        mouth_feature_model = Reshape((TIME_STEPS, -1), input_shape=(TIME_STEPS, *mouth_input_shape))

    cnn_features = mouth_feature_model(my_input_mouth_images)

    lstm_input = Concatenate()([cnn_features, my_input_head_poses])

    lstm_output = LSTM(lstm_units_1, activation='tanh', kernel_regularizer=l2(1.e-4), return_sequences=False)(lstm_input)

    concatenated_features = Concatenate()([lstm_output, my_input_n_of_frames, my_input_lipreader_dense, my_input_lipreader_softmax])

    fc1 = Dense(dense_fc_1, activation='relu', kernel_regularizer=l2(1.e-4))(concatenated_features)

    bn1 = BatchNormalization()(fc1)

    dp1 = Dropout(dropout_p)(bn1)

    fc2 = Dense(dense_fc_2, activation='relu', kernel_regularizer=l2(1.e-4))(dp1)

    bn2 = BatchNormalization()(fc2)

    dp2 = Dropout(dropout_p)(bn2)

    assessor_output = Dense(1, activation='sigmoid')(dp2)

    assessor = Model(inputs=[my_input_mouth_images, my_input_head_poses, my_input_n_of_frames, my_input_lipreader_dense, my_input_lipreader_softmax],
                     outputs=assessor_output)

    assessor.summary()

    return assessor
Пример #2
0
def get_model(model, ishape, nb_classes):
    "Return proper ResNet model"
    if model.endswith('18'):
        model = ResnetBuilder.build_resnet_18(ishape, nb_classes)
    elif model.endswith('34'):
        model = ResnetBuilder.build_resnet_34(ishape, nb_classes)
    elif model.endswith('50'):
        model = ResnetBuilder.build_resnet_50(ishape, nb_classes)
    elif model.endswith('101'):
        model = ResnetBuilder.build_resnet_101(ishape, nb_classes)
    elif model.endswith('152'):
        model = ResnetBuilder.build_resnet_152(ishape, nb_classes)
    else:
        return NotImplemented()
    return model
    def model_confirm(self, choosed_model):
        if choosed_model == 'AlexNet':
            model = alexnet(self.config)
        elif choosed_model == 'VGG16':
            model = vgg16(self.config)
        elif choosed_model == 'VGG19':
            model = vgg19(self.config)
        elif choosed_model == 'InceptionV3':
            model = inception_v3(self.config)
        elif choosed_model == 'InceptionV4':
            model = inception_v4(self.config)
        elif choosed_model == 'InceptionV4_ResNetV1':
            model = inception_resnet_v1(self.config)
        elif choosed_model == 'InceptionV4_ResNetV2':
            model = inception_resnet_v2(self.config)
        elif choosed_model == 'ResNet18':
            model = ResnetBuilder.build_resnet_18(self.config)
        elif choosed_model == 'ResNet34':
            model = ResnetBuilder.build_resnet_34(self.config)
        elif choosed_model == 'ResNet50':
            model = ResnetBuilder.build_resnet_50(self.config)
        elif choosed_model == 'ResNet101':
            model = ResnetBuilder.build_resnet_101(self.config)
        elif choosed_model == 'ResNet152':
            model = ResnetBuilder.build_resnet_152(self.config)
        elif choosed_model == 'DenseNet121':
            model = densenet121(self.config)
        elif choosed_model == 'DenseNet169':
            model = densenet169(self.config)
        elif choosed_model == 'DenseNet201':
            model = densenet201(self.config)
        elif choosed_model == 'DenseNet264':
            model = densenet264(self.config)
        else:
            model = -1

        return model
Пример #4
0
def test_resnet101():
    model = ResnetBuilder.build_resnet_101((3, 224, 224), 100)
    _test_model_compile(model)
Пример #5
0
def test_resnet101():
    for ordering in DIM_ORDERING:
        K.set_image_dim_ordering(ordering)
        model = ResnetBuilder.build_resnet_101((3, 224, 224), 100)
        model.compile(loss="categorical_crossentropy", optimizer="sgd")
        assert True, "Failed to build with '{}' dim ordering".format(ordering)
Пример #6
0
    def build_resnet_101(self, shape, num_classes):
        self.model = ResnetBuilder.build_resnet_101(shape, num_classes)

        print('[+] ResNet-101 model built')
        return self.model
Пример #7
0
def test_resnet101():
    model = ResnetBuilder.build_resnet_101((3, 224, 224), 100)
    _test_model_compile(model)