我試圖在ResNet50上爲使用Keras 2.0的多分類任務添加Flatten圖層,密集圖層(relu)和密集圖層(softmax) 0.2 Theano 0.9.0 py2.7上Win10.Here是我的代碼:嘗試在ResNet50(notop)上添加Flatten圖層並獲取錯誤
def create_model():
base_model = ResNet50(include_top=False, weights=None,
input_tensor=None, input_shape=(3,224,224),
pooling=None)
base_model.load_weights(weight_path+'/resnet50_weights_th_dim_ordering_th_kernels_notop.h5')
x = base_model.output
x = Flatten()(x)
x = Dense(128,activation='relu',kernel_initializer='random_normal',
kernel_regularizer=regularizers.l2(0.1),
activity_regularizer=regularizers.l2(0.1))(x)
x=Dropout(0.3)(x)
y = Dense(8, activation='softmax')(x)
model = Model(base_model.input, y)
for layer in base_model.layers:
layer.trainable = False
model.compile(optimizer='adadelta',
loss='categorical_crossentropy')
return model
我已經設置image_dim_ordering:
from keras import backend as K
K.set_image_dim_ordering('th')
這裏是我的Keras.json文件:
{
"backend": "theano", ``"image_data_format": "channels_first", ``"epsilon": 1e-07, ``"floatx": "float32"
}
以下是錯誤消息:
ValueError: The shape of the input to "Flatten" is not fully defined (got (2048, None, None). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.
什麼是錯誤堆棧跟蹤? – putonspectacles
我可能應該提到,如果我不添加該行,那麼一切正常工作:'base_model.load_weights(weight_path +'/ resnet50_weights_th_dim_ordering_th_kernels_notop.' – JumpyWarlock