在张量流中加载 image_dataset_from_directory 时出错?

The*_*ist 6 deep-learning conv-neural-network tensorflow jupyter-notebook

这是来自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,
)
Run Code Online (Sandbox Code Playgroud)

错误是

---------------------------------------------------------------------------
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'
Run Code Online (Sandbox Code Playgroud)

我现在忽略的任何最小细节?

Adi*_*ely 10

v2.5.0
我使用该代码得到了同样的错误:

tf.keras.utils.image_dataset_from_directory(...)
Run Code Online (Sandbox Code Playgroud)

将其更改为:

tf.keras.preprocessing.image_dataset_from_directory(...)
Run Code Online (Sandbox Code Playgroud)

解决我的问题


col*_*exe 6

它已在此问题下得到解决。

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并继续。