【发布时间】:2016-06-05 12:22:59
【问题描述】:
我正在尝试学习一些 Keras 语法并使用 Inception v3 example
我有一个 4 类多类分类玩具问题,所以我从示例中更改了以下几行:
NB_CLASS = 4 # number of classes
DIM_ORDERING = 'tf' # 'th' (channels, width, height) or 'tf' (width, height, channels)
我的玩具数据集具有以下维度:
- 包含所有图像的数组大小:(595, 299, 299, 3)
- 包含训练图像的数组大小:(416, 299, 299, 3)
- 包含训练标签的数组大小:(179, 4)
- 包含测试图像的数组大小:(179, 299, 299, 3)
- 包含测试标签的数组大小:(179, 4)
然后我尝试使用以下代码训练模型:
# fit the model on the batches generated by datagen.flow()
# https://github.com/fchollet/keras/issues/1627
# http://keras.io/models/sequential/#sequential-model-methods
checkpointer = ModelCheckpoint(filepath="/tmp/weights.hdf5", verbose=1, save_best_only=True)
model.fit_generator(datagen.flow(X_train, Y_train,
batch_size=32),
nb_epoch=10,
samples_per_epoch=32,
class_weight=None, #classWeights,
verbose=2,
validation_data=(X_test, Y_test),
callbacks=[checkpointer])
然后我得到以下错误:
Exception: The model expects 2 input arrays, but only received one array. Found: array with shape (179, 4)`
这可能与此有关,因为 Inception 希望拥有 auxiliary classifiers (Szegedy et al., 2014):
model = Model(input=img_input, output=[preds, aux_preds])
我如何在 Keras 中为模型赋予两个标签,也不是高级 Python 程序员?
【问题讨论】:
-
ImageDataGenerator默认输出一个标签。您可以扩展该类并覆盖flow函数以生成两个输出。其他选项是单独执行增强并使用fit函数。 -
你试过'validation_data=(X_test, [Y_test, Y_test])'
-
请发布您的完整型号代码 - 否则无法找到您的错误。
-
根据 Marcin 的建议将 datagen.flow 更正为 (X_train, [Y_train,Y_train] 和验证数据。我认为这应该解决它