【问题标题】:ValueError: ('Error when checking model input: expected no data, but got:', array)ValueError:('检查模型输入时出错:预期没有数据,但得到:',数组)
【发布时间】:2019-09-18 23:42:10
【问题描述】:

我正在尝试使用我自己的图像数据构建一个 inception 和 resnet 模型。该数据集共有 8000 张图像,有 6 个标签。构建模型时一切正常。但是提到的错误发生在model.fit()。 花了 14 小时后我真的不确定问题出在哪里。

我尝试了以下

  1. 更改图像尺寸顺序

  2. 对 keras.json 进行更改

  3. 更改模型中的 input_tensor 形状

错误图片:

inception_model = InceptionV3(input_tensor = inception_model.input, include_top = True, weights = 'imagenet')
inception_last_layer = inception_model.get_layer('predictions').output
inception_out = Dense(num_classes, activation='softmax', name='output')(inception_last_layer)
custom_inception = Model(inception_model.input, inception_out)

for layer in custom_inception.layers[:-3]:
        layer.trainable = False

custom_inception.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy', 'mse', 'mae', 'mape'])
train_inception = custom_inception.fit(X_train, y_train, batch_size=8, epochs=2)

编辑:我目前正在使用 keras 2.2.0,在 github 中解决了一些 keras 问题后,我从最新版本降级了该版本。它确实解决了一些最初的问题。我目前正在使用它们各自的python文件中的inception和resnet,我对include_top=include_top进行了一些更改 require_flatten=include_top 来自this

EDIT2:这是输入形状

(1690, 220, 220, 1)  is the X_train shape
(1690, 6)  is the y_train 
(423, 220, 220, 1)  is the X_test shape
(423, 6)  is the y_test 

【问题讨论】:

  • 能否提供X_train.shapey_train.shape的结果?
  • 当然我会在几秒钟内添加一个详细的 png 形状
  • 你可以直接复制粘贴结果,用python 隔开,这样会更干净。
  • 对象是什么:inception_model.input,是张量吗?如果您使用的是 [this version fo inception] (github.com/keras-team/keras-applications/blob/master/…),看起来您的模型在构造函数中不需要此参数。
  • 是的,它是一个带形状的张量(None, image_rows, image_cols, channels)

标签: keras deep-learning


【解决方案1】:

通过以下步骤解决了这个问题:

input_tensor=Input((300,300,3))

代替

input_tensor = inception_model.input
  1. 将 tensorflow 和 keras 升级到 1.13.1 和 2.2.4
  2. 使用输入形状(300,300,3) 定义模型并在通道轴上堆叠我的(300,300,1) 输入三次以匹配(300,300,3)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    • 2019-12-22
    • 2022-11-03
    • 2019-05-04
    • 2019-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多