首页 Paddle框架 帖子详情
训练个几下就TypeError
收藏
快速回复
Paddle框架 问答深度学习模型训练炼丹技巧 962 3
训练个几下就TypeError
收藏
快速回复
Paddle框架 问答深度学习模型训练炼丹技巧 962 3

跪求大神们解答

发现问题: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'

0
收藏
回复
全部评论(3)
时间顺序
星光ld1
#2 回复于2020-06

看着报错,感觉是图片中存在无法读取的错误格式图片,然后读取出错就终止了

0
回复
星光ld1
#3 回复于2020-06

可以在图片读取部分加个try,except,进行异常捕获试试

0
回复
thinc
#4 回复于2020-06

opencv的错可以去百度google查下,基本错误都出在new_img

可以把shape和内容都打印下

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户