【发布时间】:2021-05-25 17:48:25
【问题描述】:
我创建了一个神经网络来帮助识别儿童的图像并根据预先训练的标准给他们评分。问题是我使用的网络 scraper 必须下载了未知文件或 tensorflow 不支持的文件才能与 NN 一起使用。我将两个训练和验证目录分为 5 个单独的类别,允许根据类别为每个图像指定一个标签。我尝试运行一个基本循环来打印损坏或丢失的文件,但它不会显示正确的文件。我的模型在编译 fit 语句时抛出错误并给我一个
"PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x0000022B6AC4E900>" 错误。这是我用来快速遍历目录以搜索错误文件的代码,因为它似乎是 webp 问题。
filepaths = [V, T]
bad_file = []
for fp in filepaths:
# Split the extension from the path
ext = os.path.splitext(fp)[-1].lower()
if ext == ".jpg":
print (fp, "is an jpg!")
elif ext == ".jpeg":
print (fp, "is a jpeg file!")
#elif ext == ".webp":
# print (fp, "is a flac file!")
elif ext == ".png":
print (fp, "is a png file!")
else:
bad_file.append(fp)
#os.remove(fp)
print (fp, "is an unknown file format.")
print(bad_file)
任何帮助 A) 尝试解码 io_bytes 图像,因为我找不到可靠且干净的源 b) 帮助编写一个函数来搜索目录中的错误文件
非常感谢任何和所有帮助!谢谢!
【问题讨论】:
标签: python tensorflow neural-network tf.keras