简体   繁体   English

'BatchDataset' object 没有属性 'shape'

[英]'BatchDataset' object has no attribute 'shape'

Here is my code:这是我的代码:

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)

The error is:错误是:

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

How can I solve the error?我该如何解决错误?
Thanks.谢谢。

Because image_dataset_from_directory returns a tf.data.Dataset which has no shape attribute.因为image_dataset_from_directory返回一个没有shape属性的tf.data.Dataset And you can see how to use the tf.reshape function here :你可以在这里看到如何使用tf.reshape function :

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM