输入张量的输入形状无效

问题描述 投票:0回答:1

番茄项目

模型正在构建,但拒绝训练。它说输入形状的格式不正确,我已经尝试了我所知道的一切可能的方法。模型误差为

Epoch 1/50
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[70], line 1
----> 1 history = model.fit(
      2     train_ds,
      3     epochs = EPOCHS,
      4     batch_size = BATCH_SIZE,
      5     verbose =1,
      6     validation_data = val_ds
      7 )

File /opt/conda/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py:122, in filter_traceback.<locals>.error_handler(*args, **kwargs)
    119     filtered_tb = _process_traceback_frames(e.__traceback__)
    120     # To get the full stack trace, call:
    121     # `keras.config.disable_traceback_filtering()`
--> 122     raise e.with_traceback(filtered_tb) from None
    123 finally:
    124     del filtered_tb

File /opt/conda/lib/python3.10/site-packages/keras/src/models/functional.py:285, in Functional._adjust_input_rank(self, flat_inputs)
    283             adjusted.append(ops.expand_dims(x, axis=-1))
    284             continue
--> 285     raise ValueError(
    286         f"Invalid input shape for input {x}. Expected shape "
    287         f"{ref_shape}, but input has incompatible shape {x.shape}"
    288     )
    289 # Add back metadata.
    290 for i in range(len(flat_inputs)):

ValueError: Exception encountered when calling Sequential.call().

Invalid input shape for input Tensor("data:0", shape=(None, 256, 256, 3), dtype=float32). Expected shape (256, 256), but input has incompatible shape (None, 256, 256, 3)

Arguments received by Sequential.call():
  • inputs=tf.Tensor(shape=(None, 256, 256, 3), dtype=float32)
  • training=True
  • mask=None
python tensorflow deep-learning
1个回答
0
投票

当我将批量大小删除到我的数据集中时,我也遇到同样的错误,它可以工作,但不知道如何处理批量大小

# train_dataset = train_dataset.shuffle(buffer_size=1024).batch(32).prefetch(tf.data.AUTOTUNE)
# test_dataset = test_dataset.batch(32).prefetch(tf.data.AUTOTUNE)

© www.soinside.com 2019 - 2024. All rights reserved.