This is the code from https://keras.io/examples/vision/image_classification_from_scratch/
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
# generate a dataset
image_size = (180,180)
batch_size = 32
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
"PetImages",
validation_split = 0.2,
subset = "training",
seed = 1337,
image_size = image_size,
batch_size = batch_size,
)
Error is
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-21-bb7f2d14bf63> in <module>
3 batch_size = 32
4
----> 5 train_ds = tf.keras.preprocessing.image_dataset_from_directory(
6 "PetImages",
7 validation_split = 0.2,
AttributeError: module 'tensorflow.keras.preprocessing' has no attribute 'image_dataset_from_directory'
Any smallest detail which I am overlooking now?
image_dataset_from_directory allows to load your data in the tf. data. Dataset format. Hence, it enables also the use, and this is the best, of the Keras preprocessing layers, including data augmentation.
Used in the notebooks. Then calling image_dataset_from_directory(main_directory, labels='inferred') will return a tf. data. Dataset that yields batches of images from the subdirectories class_a and class_b , together with labels 0 and 1 (0 corresponding to class_a and 1 corresponding to class_b ).
Keras Preprocessing is the data preprocessing and data augmentation module of the Keras deep learning library. It provides utilities for working with image data, text data, and sequence data.
It has been addressed under this issue.
The specific function (tf.keras.preprocessing.image_dataset_from_directory) is not available under TensorFlow v2.1.x or v2.2.0 yet. It is only available with the tf-nightly builds and is existent in the source code of the master branch.
Too bad they didn't indicate it anywhere on site. Better to use flow_from_directory
for now. Or switch to tf-nightly
and carry on.
v2.5.0
I got the same error using that code:
tf.keras.utils.image_dataset_from_directory(...)
changing it to:
tf.keras.preprocessing.image_dataset_from_directory(...)
fix my problem
I also had the same problem. When I upgraded the TensorFlow version to 2.3.0, it worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With