2017-08-07 201 views
0

我想要做的是在導入的VGG16模型前添加一個Upsampling2D圖層。然而,我不知道如何做到這一點,從未在互聯網上的任何地方看到過這樣的事情。Keras - 在模型前添加一層

我試圖這樣做:

VGG = VGG16() 
model = Sequential() 
model.add(UpSampling2D((32,32), input_shape=(7,7,3))) 
model.add(VGG) 

但試圖利用這個模型任何會引發以下錯誤:

AttributeError: Layer model_1 has multiple inbound nodes, hence the notion of "layer output" is ill-defined. Use get_output_at(node_index) instead.

任何想法,爲什麼?

回答

0

您可以在VGG16()中提供input_tensor參數。

from keras.applications.vgg16 import VGG16 
from keras.layers import Input, UpSampling2D 
input_tensor = Input(shape=(7, 7, 3)) 
upsampled = UpSampling2D((32, 32))(input_tensor) 
VGG = VGG16(input_tensor=upsampled) 

通過運行VGG.summary(),你應該看到類似:

_________________________________________________________________ 
Layer (type)     Output Shape    Param # 
================================================================= 
input_1 (InputLayer)   (None, 7, 7, 3)   0 
_________________________________________________________________ 
up_sampling2d_1 (UpSampling2 (None, 224, 224, 3)  0 
_________________________________________________________________ 
block1_conv1 (Conv2D)  (None, 224, 224, 64)  1792 
_________________________________________________________________ 
block1_conv2 (Conv2D)  (None, 224, 224, 64)  36928 
_________________________________________________________________ 
block1_pool (MaxPooling2D) (None, 112, 112, 64)  0 
_________________________________________________________________ 

...