tensorflow.python.framework.errors_impl.InvalidArgumentError



我正在尝试用Tensorflow 2.x检测对象。但我在训练中遇到了这样的问题。我的数据的扩展名是.jpg和.jpeg。Tensorflow不训练扩展名为.jpg的图片,你知道吗?你认为我怎样才能解决这个错误?

Tensor可以使用jpg扩展。我一直在用它们。尽管文件格式相同,但我不确定它是否会将jpeg作为扩展名,所以我使用ImageDataGenerator进行了尝试,它也能正常工作。很明显,你有其他类型的问题。我建议你使用下面的代码来遍历你的目录,并检查这些文件是否是有效的图像文件,并且具有jpg或jpeg扩展名

import os
import PIL
from PIL import Image
source_dir=r'c:tempspidersstorage'
source_list=os.listdir (source_dir)
for file in source_list:
fpath=os.path.join(source_dir, file)
try:
img=Image.open(fpath)
shape=img.size
if file.endswith('jpeg') or file.endswith( 'jpg'):
pass
else:
print ('file ', fpath, ' has an extension other than jpg or jpeg')
except:
print ('file ', fpath, ' is an invalid image file')
print ('***** process completed *****')

最新更新