我试图使用在网上找到的代码查看jpeg文件。
以下是代码:
from PIL import Image
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
image = Image.open('/kaggle/input/chest-xray-pneumonia/chest_xray/__MACOSX/chest_xray/test/PNEUMONIA/._person121_bacteria_576.jpeg')
image.show()
但是我得到这个错误:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-1-637f422434fd> in <module>
19
20
---> 21 image = Image.open('/kaggle/input/chest-xray-pneumonia/chest_xray/__MACOSX/chest_xray/test/PNEUMONIA/._person121_bacteria_576.jpeg')
22 image.show()
/opt/conda/lib/python3.6/site-packages/PIL/Image.py in open(fp, mode)
2685 warnings.warn(message)
2686 raise IOError("cannot identify image file %r"
-> 2687 % (filename if filename else fp))
2688
2689 #
OSError: cannot identify image file '/kaggle/input/chest-xray-pneumonia/chest_xray/__MACOSX/chest_xray/test/PNEUMONIA/._person121_bacteria_576.jpeg'
我想知道这是否是一个问题,因为我没有加载数据或其他东西? 我在Kagglenotebook的笔记本上没有写其他数据集:https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia
答案 0 :(得分:0)
在使用PIL模块时,我通常将文件命名为“ .jpg”,然后将引用适当的文件路径。
我用重命名的 image.jpg 文件尝试了您的代码,当我使用'.jpeg'时,它工作正常,
from PIL import Image
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
image = Image.open('/Users/GameComputerC/ocr3.jpg')
image.show()
让我知道它是否对您有用。那可能只是错误的一部分。