【问题标题】:Error in loading image_dataset_from_directory in tensorflow?在张量流中加载 image_dataset_from_directory 时出错?
【发布时间】:2020-06-16 13:36:30
【问题描述】:

这是代码 来自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'

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

【问题讨论】:

  • 这是哪个tf版本?
  • 版本是2.2.0

标签: tensorflow deep-learning jupyter-notebook conv-neural-network


【解决方案1】:

已在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 继续。

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题。当我将 TensorFlow 版本升级到 2.3.0 后,它就可以工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-27
      • 2016-03-10
      • 2018-09-29
      • 2020-12-25
      • 2018-09-11
      • 1970-01-01
      相关资源
      最近更新 更多