英文:
custom dataset for image in tensorflow 2.0
问题
我正在尝试使用TensorFlow 2.0创建“图像的自定义数据集”,我的目录结构如下:
以“PetImage\”为根目录,其中包含两个类别:猫和狗,分别包含相应的图像。
/PetImage|
|Cat
| img1.jpg
| img2.jpg
| imgn.jpg
| ...
|Dog | img1.jpg
| img2.jpg
| ig3.jpg
| ig.jpg
| ...
我的代码如下:
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)
错误信息:
InvalidArgumentError: 图执行错误:输入为空。
[[{{node decode_image/DecodeImage}}]]
[[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
| ...
|Dog | img1.jpg
| img2.jpg
| ig3.jpg
| ig.jpg
| ...
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论