简体   繁体   English

TensorFlow 在训练或验证时给出错误“InvalidArgumentError: Input is empty”

[英]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.

相关问题 读取自己图像集上的训练记录时的TensorFlow InvalidArgumentError - TensorFlow InvalidArgumentError when reading record for training on own image set 在tensorflow中评估新数据时出现InvalidArgumentError错误 - InvalidArgumentError error when evaluating new data in tensorflow InvalidArgumentError:输入_1:0被同时获取和获取,tensorflow错误,python - InvalidArgumentError: input_1:0 is both fed and fetched, error with tensorflow, python 使用 Keras 训练时的 Tensorflow InvalidArgumentError(索引) - Tensorflow InvalidArgumentError (indices) while training with Keras InvalidArgumentError:找到 2 个根错误。 (0) 无效参数:输入为空 - InvalidArgumentError: 2 root error(s) found. (0) Invalid argument: Input is empty Tensorflow:InvalidArgumentError:图形执行错误: - Tensorflow: InvalidArgumentError: Graph execution error: 提供占位符时TensorFlow InvalidArgumentError - TensorFlow InvalidArgumentError when feeding a placeholder InvalidArgumentError:训练 model 时图形执行错误 - InvalidArgumentError: Graph execution error while training model 使用TensorFlow训练神经网络时出错 - Error when training a neural network with TensorFlow 使用TensorFlow训练神经网络时dtype错误 - dtype error when training neural network with TensorFlow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM