我有一个接受过图像训练的CNN。我还获得了脸部的几何图形(带有x,y坐标的68x2-68点)。我想在所有卷积层之后对几何进行编码,并在完全连接的层中使用它们。我正在使用vggFace模型。

'''
Load the model
'''
vgg_model = VGGFace(
    include_top=False,
    input_shape=(img_width, img_height, 3))


'''
Customize the model
'''
# Add geometry input
geo_input = Input(shape=(1,136,1))
geo_input = Flatten(name='flatten')(geo_input)


last_layer = vgg_model.get_layer('pool5').output
x = Flatten(name='flatten')(last_layer)
x = concatenate([x, geo_input], axis=1)
x = Dense(hidden_dim, activation='relu', name='fc6')(x)
x = Dense(hidden_dim, activation='relu', name='fc7')(x)
out = Dense(nb_class, activation='softmax', name='fc8')(x)

custom_vgg_model = Model(
    [vgg_model.input, geo_input],
    out)


但是我收到以下错误:

TypeError: Input layers to a `Model` must be `InputLayer` objects. Received inputs: [<tf.Tensor 'input_1:0' shape=(?, 224, 224, 3) dtype=float32>, <tf.Tensor 'flatten/Reshape:0' shape=(?, ?) dtype=float32>]. Input 1 (0-based) originates from layer type `Flatten`.

最佳答案

这里:

# Add geometry input
geo_input = Input(shape=(1,136,1))
geo_input = Flatten(name='flatten')(geo_input)


在第二行中,geo_input不再是输入。它是Flatten层的输出。您正在将其传递给Model创建。因此,您需要保持正确的输入张量:

geo_input_tensor = Input(shape=(1,136,1))
geo_input = Flatten(name='flatten')(geo_input_tensor)

.....
......

custom_vgg_model = Model([vgg_model.input, geo_input_tensor], out)

关于python - Keras:将元数据串联到CNN中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46791471/

10-12 23:30