[英]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.