【发布时间】:2020-06-08 02:08:53
【问题描述】:
我正在尝试构建一个简单的分类 CNN,它将使用以下代码将一组 1233 张图像分为 4 个类别:
unclassified_datagen = keras.preprocessing.image.ImageDataGenerator(
rescale=1. / 255,
horizontal_flip=True
)
unclassified_generator = train_datagen.flow_from_directory(
'data/unclassified',
target_size=(120, 120),
batch_size=1233,
class_mode='input',
shuffle=False,
)
model_unclassified = keras.Sequential()
model_unclassified.add(layers.Conv2D(1233, (3, 3), input_shape=(120, 120, 3), padding="SAME"))
model_unclassified.add(layers.Dense(64, activation='relu'))
model_unclassified.add(layers.Dense(4, activation='sigmoid'))
model_unclassified.compile(loss='sparse_categorical_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
model_unclassified.fit_generator(unclassified_generator, epochs=1)
但我收到以下错误:ValueError: Error when checking target: expected dense_2 to have shape (120, 120, 1) but got array with shape (120, 120, 3)
我做错了什么?
【问题讨论】:
标签: python machine-learning keras neural-network