【问题标题】:ValueError: Input 0 is incompatible with layer resnet50: expected shape=(None, 180, 180, 3), found shape=(180, 180, 3)ValueError: Input 0 is in compatible with layer resnet50: expected shape=(None, 180, 180, 3), found shape=(180, 180, 3)
【发布时间】:2021-09-08 10:28:43
【问题描述】:

使用 TFF 0.18,我发现了这个问题:

images, labels = next(img_gen.flow_from_directory(path0,target_size=(180, 180), batch_size = 2,class_mode=None))
sample_batch = (images,labels)  # assumes images and labels are np.ndarray
input_spec = tf.nest.map_structure(tensor_spec_from_ndarray, sample_batch)

这是 input_spec 的输出

(TensorSpec(shape=(180, 180, 3), dtype=tf.float32, name=None), TensorSpec(shape=(180, 180, 3), dtype=tf.float32, name=None))

这是我的模型:

model = tf.keras.applications.ResNet50(include_top=False, weights=None, input_tensor=tf.keras.Input(shape=(180, 180, 3)), pooling=None)

【问题讨论】:

    标签: tensorflow tensorflow-federated


    【解决方案1】:

    在高层次上,错误消息是说张量的等级不同(4 对 3)。

    expected shape=(None, 180, 180, 3)

    预期的形状有一个前导的None 维度,即批次维度。

    found shape=(180, 180, 3)

    找到的形状只有等级 3,没有批次维度。

    问题中的代码有batch_size = 2 行,这有点令人惊讶。我将深入研究img_gen.flow_from_directory() 函数如何使用该参数,以查看是否可以获取批处理维度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-14
      • 2021-03-30
      • 2021-09-03
      • 2023-03-23
      • 2022-09-24
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多