[英]TensorFlow giving error “InvalidArgumentError: Input is empty” when training or validating
I am trying to run the Resnet model on custom images (transfer learning).我正在尝试在自定义图像上运行 Resnet 模型(迁移学习)。
My directory tree looks like this:我的目录树如下所示:
|-train
| |-class1
| | |-image1
| | |-image2
| | |-....
| |-class2
| |-image1
| |-image2
| |-....
|-val
|-class1
| |-image1
| |-image2
| |-....
|-class2
|-image1
|-image2
|-....
And I created the tensorflow datasets like this:我创建了这样的 tensorflow 数据集:
train_ds = tf.keras.preprocessing.image_dataset_from_directory( "train", labels='inferred', label_mode='int', image_size=(img_height, img_width), batch_size=batch_size)
val_ds = tf.keras.preprocessing.image_dataset_from_directory( "val", labels='inferred', label_mode='int', image_size=(img_height, img_width), batch_size=batch_size)
But when I train or test the dataset, after a few images it gives me an error:但是当我训练或测试数据集时,在几张图像之后它给了我一个错误:
InvalidArgumentError: Input is empty [[{{node decode_image/DecodeImage}}]] [Op:IteratorGetNext]
<Figure size 720x720 with 0 Axes>.
The dataset I am using is here - https://github.com/xuequanlu/I-Nema - and I have converted all the .tif
images to .jpg
.我使用的数据集在这里 - https://github.com/xuequanlu/I-Nema - 我已将所有
.tif
图像转换为.jpg
。 What could be causing this?什么可能导致这种情况?
Thanks in advance!提前致谢!
EDIT: here is the error log: https://pastecode.io/s/82hk68ar编辑:这是错误日志: https : //pastecode.io/s/82hk68ar
in your code you have在你的代码中你有
train_ds = tf.keras.preprocessing.image_dataset_from_directory( "train", labels='inferred', label_mode='int', image_size=(img_height, img_width), batch_size=batch_size)
"train" should be the full path to the directory with the training images not a string. “train”应该是包含训练图像而不是字符串的目录的完整路径。 for example train_dir=os.path.join(my_dir, 'train') where my_dir holds the train and val sub directories
例如 train_dir=os.path.join(my_dir, 'train') 其中 my_dir 保存 train 和 val 子目录
train_dir=os.path.join(my_dir, 'train')
val_dir=os.path.join(my_dir, 'val')
train_ds = tf.keras.preprocessing.image_dataset_from_directory( train_dir, labels='inferred', label_mode='int', image_size=(img_height, img_width), batch_size=batch_size)
val_ds = tf.keras.preprocessing.image_dataset_from_directory( val_dir, labels='inferred', label_mode='int', image_size=(img_height, img_width), batch_size=batch_size)
Also note since you are using label_mode='int' then in model.compile specify the loss as sparse_categorical_crossentropy另请注意,由于您使用的是 label_mode='int' 然后在 model.compile 中将损失指定为 sparse_categorical_crossentropy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.