【问题标题】:Image classification: ValueError: too many values to unpack (expected 2)图片分类:ValueError: too many values to unpack (expected 2)
【发布时间】:2020-09-23 06:09:44
【问题描述】:

我正在练习图像分类项目。我得到了

这是我使用的代码。任何人都可以建议我在哪里做错了。

# Predict
test_batch_x, test_batch_y = test_gen.next()
pred_batch = model.predict(test_batch_x)

test_labels = np.argmax(test_batch_y, axis=1)
test_pred = np.argmax(pred_batch, axis=1)

它在test_batch_x, test_batch_y = test_gen.next() 抛出这个错误

 ValueError: too many values to unpack (expected 2)

有人可以对此提出建议吗?

【问题讨论】:

    标签: python image-processing keras deep-learning transfer-learning


    【解决方案1】:

    看来,next() 方法没有返回两个值, 但是您尝试将结果解压缩为两个变量。

    由于您使用flow_from_directory 创建了test_gen,因此它是一个tf.data.Dataset:https://www.tensorflow.org/api_docs/python/tf/data/Dataset

    我认为 next 只返回一个值,因为没有定义标签 class_mode=None

    【讨论】:

    • test_gen = datagen.flow_from_directory(directory=TEST_DIR, target_size=(IMG_HEIGHT, IMG_WIDTH), batch_size=TEST_BATCH_SIZE, class_mode=None, shuffle=False)
    • 谢谢。我认为你应该在问题中包含这个。 class_mode=None 确实禁用标签,所以这可能是next() 只返回一个值而不是图像 - 标签对的原因。
    猜你喜欢
    • 2019-02-01
    • 2019-01-19
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多