【问题标题】:'BatchDataset' object has no attribute 'shape'\'BatchDataset\' 对象没有属性 \'shape\'
【发布时间】:2022-11-26 09:36:53
【问题描述】:

这是我的代码:

train_images = tf.keras.utils.image_dataset_from_directory(
  '/content/drive/MyDrive/ArabicHandwritten2/train')

train_labels = tf.keras.utils.image_dataset_from_directory(
  '/content/drive/MyDrive/ArabicHandwritten2/test')

train_images = tf.reshape(train_images.shape[0], 256, 256, 3).astype('float32')
train_images = (train_images - 127.5) / 127.5 # Normalize the images to [-1, 1]

BUFFER_SIZE = 16765
BATCH_SIZE = 32

train_dataset = tf.data.Dataset.from_tensor_slices(train_images).shuffle(BUFFER_SIZE).batch(BATCH_SIZE)

错误是:

AttributeError: 'BatchDataset' object has no attribute 'shape'

我该如何解决错误?
谢谢。

【问题讨论】:

  • 我们能看到整个回溯吗?

标签: python tensorflow shapes reshape


【解决方案1】:

因为image_dataset_from_directory 返回一个没有shape 属性的tf.data.Dataset。你可以看到如何使用tf.reshape函数here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-28
    • 2018-01-22
    • 2016-07-31
    • 2022-08-21
    • 2019-11-18
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    相关资源
    最近更新 更多