自定义数据集用于 TensorFlow 2.0 中的图像。

huangapple go评论87阅读模式
英文:

custom dataset for image in tensorflow 2.0

问题

我正在尝试使用TensorFlow 2.0创建“图像的自定义数据集”,我的目录结构如下:

  1. 以“PetImage\”为根目录,其中包含两个类别:猫和狗,分别包含相应的图像。
  2. /PetImage|
  3. |Cat
  4. | img1.jpg
  5. | img2.jpg
  6. | imgn.jpg
  7. | ...
  8. |Dog | img1.jpg
  9. | img2.jpg
  10. | ig3.jpg
  11. | ig.jpg
  12. | ...

我的代码如下:

  1. img_height = 64
  2. img_width = 64
  3. ds_train = tf.keras.preprocessing.image_dataset_from_directory(
  4. "I:\\Image\\Data\\kagglecatsanddogs_5340\\PetImages",
  5. labels="inferred",
  6. label_mode="int",
  7. color_mode="rgb",
  8. image_size=(img_height, img_width),
  9. shuffle=True,
  10. seed=123,
  11. validation_split=0.3,
  12. subset="training",
  13. interpolation="bicubic"
  14. )
  15. history = model.fit(ds_train, epochs=2)

错误信息:

  1. InvalidArgumentError: 图执行错误:输入为空。
  2. [[{{node decode_image/DecodeImage}}]]
  3. [[IteratorGetNext]] [Op:__inference_train_function_1704]
英文:

I am trying to "custom dataset for image" using tensorflow 2.0
my directory structure is:
say (PetImage)as root directory which contains two classes: Cat and Dog which contains respective images.
/PetImage|
|Cat
| img1.jpg
| img2.jpg
| imgn.jpg
| ...

  1. |Dog | img1.jpg
  2. | img2.jpg
  3. | ig3.jpg
  4. | ig.jpg
  5. | ...

My code is as follows:
img_height = 64
img_width = 64

ds_train = tf.keras.preprocessing.image_dataset_from_directory(
"I:\Image\Data\kagglecatsanddogs_5340\PetImages",
labels="inferred",
label_mode="int",
color_mode="rgb",
image_size=(img_height, img_width),
shuffle=True,
seed=123,
validation_split=0.3,
subset="training",
interpolation="bicubic"
)

history = model.fit(ds_train, epochs=2)

Error:

InvalidArgumentError: Graph execution error:

Input is empty.
[[{{node decode_image/DecodeImage}}]]
[[IteratorGetNext]] [Op:__inference_train_function_1704]

答案1

得分: 0

在TensorFlow 2.0中,不存在tf.keras.preprocessing.image_dataset_from_directory()函数,甚至在最新版本的TensorFlow 2.11中也没有这个函数,但有一个名为tf.keras.utils.image_dataset_from_directory()的函数。

请参考此链接 - "https://www.tensorflow.org/api_docs/python/tf/keras/utils/image_dataset_from_directory"。

英文:

In tensorflow 2.0, there is no function - tf.keras.preprocessing.image_dataset_from_directory() and even in the latest version of tensorflow 2.11 there is a function tf.keras.utils.image_dataset_from_directory()

Refer to this link - "https://www.tensorflow.org/api_docs/python/tf/keras/utils/image_dataset_from_directory"

huangapple
  • 本文由 发表于 2023年4月4日 12:16:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75925478.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定