【发布时间】:2019-02-13 00:13:19
【问题描述】:
我正在尝试将迁移学习应用于我的ANN 进行图像分类。
我找到了一个例子,我会个性化网络。
这里有主要的代码块:
model = VGG19(weights='imagenet',
include_top=False,
input_shape=(224, 224, 3))
batch_size = 16
for layer in model.layers[:5]:
layer.trainable = False
x = model.output
x = Flatten()(x)
x = Dense(1024, activation="relu")(x)
x = Dense(1024, activation="relu")(x)
predictions = Dense(16, activation="sigmoid")(x)
model_final = Model(input = model.input, output = predictions)
model_final.fit_generator(
train_generator,
samples_per_epoch = nb_train_samples,
epochs = epochs,
validation_data = validation_generator,
validation_steps = nb_validation_samples,
callbacks = [checkpoint, early])
当我运行上面的代码时,我得到了这个错误:
ValueError: Error when checking target: expected dense_3 to have shape (16,) but got array with shape (1,).
我想问题出在dense 层中的尺寸顺序,我尝试转置它,但我得到了同样的错误。
【问题讨论】:
标签: python keras keras-layer