2017-10-17 95 views
1

我有一個CNN圖像訓練。我還獲得了臉部的幾何圖形(68x2-68個點,x,y座標)。我想在所有卷積層之後編碼幾何圖形,並在完全連接的圖層中使用它們。我正在使用vggFace模型。Keras:將元數據連接成CNN

''' 
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`. 

回答

1

這裏:

# 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)