【Python】读取文件时显示 ‘NoneType‘ object has no attribute ‘shape‘

今天自己用爬虫制作数据集,在用之前能够正常运行的网络去训练爬虫爬下的数据时。显示了一个这样的错误:

Exception in thread Thread-16: Traceback (most recent call last):
File
“/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py”,
line 926, in _bootstrap_inner
self.run() File “/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py”,
line 870, in run
self._target(*self._args, **self._kwargs) File “/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/reader/decorator.py”,
line 400, in handle_worker
r = mapper(sample) File “/home/aistudio/MyDataLoader.py”, line 37, in train_mapper
is_train=True) File “/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/dataset/image.py”,
line 357, in simple_transform
im = resize_short(im, resize_size) File “/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/dataset/image.py”,
line 215, in resize_short
h, w = im.shape[:2] AttributeError: ‘NoneType’ object has no attribute ‘shape’

这大概是指读取到的图片维数不对,然后我试着通过:

if(str(type(img))==""):
    print(path)

这两行代码,获取出错图片的路径。发现图片没有背景,导致读取是出错。删除后问题解决。

在这里插入图片描述

你可能感兴趣的:(Python,python,开发语言)