【发布时间】:2017-09-04 09:00:39
【问题描述】:
我正在尝试在 ResNet50 上添加一个 Flatten 层、一个 Dense 层(relu)和一个 Dense 层(softmax),以便在 Win10 上使用 Keras 2.0.2 Theano 0.9.0 py2.7 进行多分类任务。这里是我的代码:
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.
【问题讨论】:
-
错误堆栈跟踪是什么?
-
我可能应该提到,如果我不添加该行,那么一切正常:
base_model.load_weights(weight_path+'/resnet50_weights_th_dim_ordering_th_kernels_notop.
标签: python neural-network theano keras