这是来自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,
)
错误是
---------------------------------------------------------------------------
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'
有没有我现在忽略的最小细节?
发布于 2020-06-16 22:49:02
它已经在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.
可惜他们没有在现场的任何地方指出这一点。现在最好使用flow_from_directory
。或者切换到tf-nightly
并继续。
发布于 2020-09-08 07:16:21
我也有同样的问题。当我将TensorFlow版本升级到2.3.0时,它起作用了。
https://stackoverflow.com/questions/62409838
复制相似问题