问题描述
我正在尝试按照 this Keras 教程进行图像分割。它似乎在 Colab 中运行良好,但在本地运行时,出现以下错误:
for j,path in enumerate(batch_target_img_paths):
img = load_img(path,target_size=self.img_size,color_mode="grayscale")
...
Exception has occurred: UnidentifiedImageError
cannot identify image file <_io.BytesIO object at 0x0000020130390400>
File "C:\Computer Vision\main_tutorial.py",line 203,in __getitem__
img = load_img(path,color_mode="grayscale")
File "C:\Computer Vision\main_tutorial.py",line 102,in main
model.fit(train_gen,epochs=epochs,validation_data=val_gen,callbacks=callbacks)
File "C:\Computer Vision\main_tutorial.py",line 211,in <module>
main()
我已验证路径正确:
C:\Computer Vision\oxford-iiit-pet\train\annotations\._Abyssinian_10.png
有问题的文件 ._Abyssinian_10.png
似乎不是一个有效的图像(我相信它是一个目标掩码)并且无法在常规图像查看应用程序中打开。
是否存在我遗漏的环境或平台问题?
解决方法
如果您遇到此错误,则图像可能已损坏或 step1 <- tabl %>% arrange(grp,trial,yr) %>% filter(trial != 'Y') %>%
group_by(grp) %>%
mutate(Value1.1 = cumsum(value1),Value2.1 = lag(cumsum(value2),default = 0),Value3 = Value1.1 + Value2.1)
step2 <- tabl %>% arrange(grp,yr) %>% filter(trial != 'X') %>%
group_by(grp) %>%
mutate(Value1.1 = cumsum(value1),Value3 = Value1.1 + Value2.1)
desired_outcome <- rbind(step1,step2 %>% filter(trial != 'B')
) %>% select(-Value1.1,-Value2.1) %>% arrange(grp,yr)
。
根据我的经验,您无法挽救此图像,最好使用下面的代码将其删除,该代码检查图像是否作为 NoneType
有效,如果不是,则删除该图像。如果您有 PNG
张图片,那么您可以使用 JPEG
代替。
您必须在图像的整个目录中运行它。
jpeg
,
这个错误是我的错误。
annotations/trimaps
文件夹包含每个原始图像的两个文件:
._Abyssinian_1.png
Abyssinian_1.png
我试图加载不正确的文件 ._Abyssinian_1.png
,我应该在其中加载 Abyssinian_1.png