跪求大神们解答
发现问题:gpu为0,显存很大
疑似:PIL转cv2出问题
部分源码:
img = Image.open(content['annotations'][ig_index]['name'])
#img = cv2.imread(content['annotations'][ig_index]['name'])
train_img_size = (640,480)
img = img.resize(train_img_size)
#img = cv2.resize(img, train_img_size)
im = np.array(img)
im = im /255.0
im = im.transpose()
ann = content['annotations'][ig_index]['annotation']
lab_img = []
for b_l in range(len(ann)):
if 'w' in ann[b_l].keys():
box = (ann[b_l]['x'],ann[b_l]['y'],ann[b_l]['x']+ann[b_l]['w'],ann[b_l]['y']+ann[b_l]['h'])
new_img = img.crop(box=box)
new_img = cv2.cvtColor(np.array(new_img),cv2.COLOR_RGB2BGR)
出错
/home/aistudio/external-libraries/imgaug/augmenters/segmentation.py:272: FutureWarning: skimage.measure.label's indexing starts from 0. In future version it will start from 1. To disable this warning, explicitely set the `start_label` parameter to 1.
image, n_segments=n_segments_samples[i], compactness=10)
Pass:0, Batch:0, Cost:8.33018, Accuracy:0.00000
Pass:0, Batch:10, Cost:6.36659, Accuracy:0.00000
Pass:0, Batch:20, Cost:7.42431, Accuracy:0.00000
Pass:0, Batch:30, Cost:4.81812, Accuracy:0.00000
Pass:0, Batch:40, Cost:8.08407, Accuracy:0.00000
Pass:0, Batch:50, Cost:3.92131, Accuracy:0.00000
Pass:0, Batch:60, Cost:3.88836, Accuracy:1.00000
Pass:0, Batch:70, Cost:4.25534, Accuracy:0.00000
Pass:0, Batch:80, Cost:3.52870, Accuracy:0.00000
Pass:0, Batch:90, Cost:4.40398, Accuracy:0.00000
Pass:0, Batch:100, Cost:3.79018, Accuracy:0.00000
Pass:0, Batch:110, Cost:2.53949, Accuracy:1.00000
Pass:0, Batch:120, Cost:3.71786, Accuracy:0.00000
Pass:0, Batch:130, Cost:5.53768, Accuracy:0.00000
Pass:0, Batch:140, Cost:7.28350, Accuracy:0.00000
Pass:0, Batch:150, Cost:4.19177, Accuracy:0.00000
Pass:0, Batch:160, Cost:0.68209, Accuracy:1.00000
Pass:0, Batch:170, Cost:3.00048, Accuracy:1.00000
Pass:0, Batch:180, Cost:3.53558, Accuracy:0.00000
Pass:0, Batch:190, Cost:3.29988, Accuracy:0.00000
Pass:0, Batch:200, Cost:2.86618, Accuracy:0.00000
Pass:0, Batch:210, Cost:7.29805, Accuracy:0.00000
Pass:0, Batch:220, Cost:5.24810, Accuracy:0.00000
---------------------------------------------------------------------------TypeError Traceback (most recent call last) in
4 for epochs in range(EPOCH_NUM):
5 # 开始训练
----> 6 for batch_id, train_data in enumerate(train_reader()): #遍历train_reader的迭代器,并为数据加上索引batch_id
7 train_cost,train_acc = exe.run(program=main_program, #运行主程序
8 feed=feeder.feed(train_data), #喂入一个batch的数据
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/batch.py in batch_reader()
33 r = reader()
34 b = []
---> 35 for instance in r:
36 b.append(instance)
37 if len(b) == batch_size:
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/reader/decorator.py in data_reader()
99 def data_reader():
100 buf = []
--> 101 for e in reader():
102 buf.append(e)
103 if len(buf) >= buf_size:
in inner()
122 box = (ann[b_l]['x'],ann[b_l]['y'],ann[b_l]['x']+ann[b_l]['w'],ann[b_l]['y']+ann[b_l]['h'])
123 new_img = img.crop(box=box)
--> 124 new_img = cv2.cvtColor(np.array(new_img),cv2.COLOR_RGB2BGR)
125 new_img = image_augment_imgauglib(new_img)
126 la_im = np.array(new_img) #由于存在Image.size=(3,0)的格式
TypeError: Expected Ptr for argument '%s'
看着报错,感觉是图片中存在无法读取的错误格式图片,然后读取出错就终止了
可以在图片读取部分加个try,except,进行异常捕获试试
opencv的错可以去百度google查下,基本错误都出在new_img
可以把shape和内容都打印下