简体   繁体   English

PIL.UnidentifiedImageError:无法识别图像文件'/NGC-DL-CONTAINER-LICENSE'

[英]PIL.UnidentifiedImageError: cannot identify image file '/NGC-DL-CONTAINER-LICENSE'

I have some errors with PILLOW.我对 PILLOW 有一些错误。 first I am import images from PIL after that working with a pillow首先我从 PIL 导入图像,然后使用枕头

but after some time I got some error line PIL.UnidentifiedImageError: cannot identify image file '/NGC-DL-CONTAINER-LICENSE'但过了一段时间我得到了一些错误行PIL.UnidentifiedImageError: cannot identify image file '/NGC-DL-CONTAINER-LICENSE'

code:代码:

from PIL import Image, ImageFilter

from PIL import Image, ImageFilter, ImageOps, ImageChops
...
...
inputs = torch.Tensor(1, 3, 16, 240, 320)
x_time = [jj for jj in range(len(img))]
y_pred = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for num, i in enumerate(img):
    if num < 16:
        inputs[:,:,num,:,:] = ToTensor(1)(Image.open(i))
        cv_img = cv2.imread(i)
        print(cv_img.shape)
        h,w,_ =cv_img.shape
        cv_img = cv2.putText(cv_img, 'FPS : 0.0, Pred : 0.0', (5,15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,200,240), 2)

error:错误:

Traceback (most recent call last):
  File "vis.py", line 135, in <module>
    inputs[:,:,num,:,:] = ToTensor(1)(Image.open(i))
  File "/usr/local/lib/python3.7/dist-packages/PIL/Image.py", line 3148, in open
    "cannot identify image file %r" % (filename if filename else fp)
PIL.UnidentifiedImageError: cannot identify image file '/NGC-DL-CONTAINER-LICENSE'

How to resolve this issue any answers and suggestions are highly recommended.如何解决这个问题强烈推荐任何答案和建议。

for more code: https://github.com/seominseok0429/Real-world-Anomaly-Detection-in-Surveillance-Videos-pytorch/blob/main/vis.py更多代码: https://github.com/seominseok0429/Real-world-Anomaly-Detection-in-Surveillance-Videos-pytorch/blob/main/vis.py

It seems like your list of images, img contain file names that are NOT images, eg, '/NGC-DL-CONTAINER-LICENSE' .看起来您的图像列表img包含不是图像的文件名,例如'/NGC-DL-CONTAINER-LICENSE'

How did you construct this list?你是如何构建这个列表的?

You can avoid this in your code:您可以在代码中避免这种情况:

for num, i in enumerate(img):
    if num < 16:
        try:
            inputs[:,:,num,:,:] = ToTensor(1)(Image.open(i))
        except PIL.UnidentifiedImageError:
            print(f'Got non-image file {i} - skipping...')
            continue
        cv_img = cv2.imread(i)
        print(cv_img.shape)
        h,w,_ =cv_img.shape
        cv_img = cv2.putText(cv_img, 'FPS : 0.0, Pred : 0.0', (5,15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,200,240), 2)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 PIL 打开 Tif 文件“PIL.UnidentifiedImageError:无法识别图像文件” - Opening Tif file with PIL “PIL.UnidentifiedImageError: cannot identify image file” PIL.UnidentifiedImageError:无法识别图像文件'image-playground/.DS_Store' - PIL.UnidentifiedImageError: cannot identify image file 'image-playground/.DS_Store' 引发 UnidentifiedImageError(PIL.UnidentifiedImageError: 无法识别图像文件 &lt;_io.BytesIO object at 0x0000018CA596D350&gt; - raise UnidentifiedImageError( PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x0000018CA596D350> Discord.py 错误,PIL.UnidentifiedImageError: 无法识别图像文件 - Discord.py error, PIL.UnidentifiedImageError: cannot identify image file PIL.UnidentifiedImageError:无法识别图像文件 <_io.BytesIO object - PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object PIL.UnidentifiedImageError: 无法识别图像文件 &#39;dataset\\\\Thumbs.db&#39; - PIL.UnidentifiedImageError: cannot identify image file 'dataset\\Thumbs.db' PIL.UnidentifiedImageError: 无法识别图像文件 [当我使用 Keras 而不是 PILLOW 时] - PIL.UnidentifiedImageError: cannot identify image file [When I using Keras and not PILLOW] Python 错误:PIL.UnidentifiedImageError:无法识别图像文件 &lt;_io.BytesIO object at 0x1144e9860&gt; - Python error: PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x1144e9860> UnidentifiedImageError:无法识别图像文件 - UnidentifiedImageError: cannot identify image file 如何在 except 中捕获 PIL.UnidentifiedImageError - how to catch PIL.UnidentifiedImageError in except
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM