【问题标题】:ValueError: `generator` yielded an element of shape (2, 200, 200, 3) where an element of shape (4, 200, 200, 3) was expectedValueError: `generator` 产生了一个形状为 (2, 200, 200, 3) 的元素,其中需要一个形状为 (4, 200, 200, 3) 的元素
【发布时间】:2020-07-05 21:48:14
【问题描述】:

我用 batch_size = 4 构造我的生成器函数,如下所示:

tf.data.Dataset.from_generator(img_gen, output_types=(tf.float32, tf.float32), output_shapes = ([4,200,200,3],[4,2]))

运行后发现这个错误

ValueError: `generator` yielded an element of shape (2, 200, 200, 3) where an element of shape (4, 200, 200, 3) was expected.

我无法理解为什么?

【问题讨论】:

  • 因为img_gen 产生了错误的元素?如果没有那个生成器,就很难知道发生了什么。

标签: python python-3.x tensorflow2.x


【解决方案1】:

可能的原因是数据示例的数量不能被批量大小整除。将您的数据安排为批量大小的倍数,或者更好的是,让后续代码适用于任何批量大小。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 2022-07-04
    • 2022-01-09
    • 2018-04-29
    相关资源
    最近更新 更多