faster_rcnn_r50_1x预测数据生成的问题
Created by: atczyh
已使用faster_rcnn_r50_1x使用自定义数据集训练一只模型,在参考paddledetection infer.py文件生成预测数据时遇到了如下问题,我提取infer文件中关于数据生成的部分代码,做成数据生成的class,如下所示:
class getdata(object):
def __init__(self, path, config):
self.imgpath = path
self.config=config
def getinferdata(self):
from ppdet.core.workspace import create,load_config
from ppdet.modeling.model_input import create_feed
from ppdet.data.data_feed import create_reader
cfg = load_config(self.config)
test_feed = create(cfg.test_feed)#FasterRCNNTestFeed
#print('test_feed1',test_feed,cfg.test_feed)#<class 'ppdet.data.data_feed.FasterRCNNTestFeed'>
#添加图片到test_feed ppdet.data.data_feed.FasterRCNNTestFeed
#print(type(test_feed))
test_images = get_test_images(None, self.imgpath)
test_feed.dataset.add_images(test_images)
loader, feed_vars = create_feed(test_feed, iterable=True)#ppdet.modeling.model_input
#print('feed_vars',type(feed_vars),feed_vars)
reader = create_reader(test_feed)
#print(loader.feed_list)
place =fluid.CPUPlace()
loader.set_sample_list_generator(reader,place)
for iter_id, data in enumerate(loader()):
print('1',iter_id, type(data),data)
del place,test_images,create,create_feed,create_reader,reader,loader,test_feed
gc.collect()
return data
return None
john = getdata("ls/004186.jpg",'configs/faster_rcnn_r50_1x.yml')
data=john.getinferdata()
print(data)
del john,data
gc.collect()
json1 = getdata("PaddleDetection/000003.jpg",'configs/faster_rcnn_r50_1x.yml')
data=json1.getinferdata()
print(data)
这个类第一次调用可以成功生成预测数据,但是调用第二次就会报错,输出数据如下:
num_scale 1(第一次调用成功)
1 0 <class 'list'> [{'im_shape': <paddle.fluid.core_avx.LoDTensor object at 0x7fb1be48eed8>, 'im_id': <paddle.fluid.core_avx.LoDTensor object at 0x7fb1f7b85768>, 'im_info': <paddle.fluid.core_avx.LoDTensor object at 0x7fb1be88edf8>, 'image': <paddle.fluid.core_avx.LoDTensor object at 0x7fb1be4916f8>}]
[{'im_shape': <paddle.fluid.core_avx.LoDTensor object at 0x7fb1be48eed8>, 'im_id': <paddle.fluid.core_avx.LoDTensor object at 0x7fb1f7b85768>, 'im_info': <paddle.fluid.core_avx.LoDTensor object at 0x7fb1be88edf8>, 'image': <paddle.fluid.core_avx.LoDTensor object at 0x7fb1be4916f8>}]
num_scale 1(第二次调用失败)
2020-01-05 17:48:40,898-WARNING: fail to map op [ArrangeTestRCNN_f24b57] with error: 'tuple' object has no attribute 'keys' and stack:
Traceback (most recent call last):
File "/home/zengyihui/Documents/PaddleDetection/ppdet/data/transform/__init__.py", line 77, in _mapper
out = f(sample, ctx)
File "/home/zengyihui/Documents/PaddleDetection/ppdet/data/transform/arrange_sample.py", line 159, in __call__
keys = sorted(list(sample.keys()))
AttributeError: 'tuple' object has no attribute 'keys'
2020-01-05 17:48:40,898-WARNING: consumer failed with error: failed to map consumer[%s], error: 'tuple' object has no attribute 'keys'
2020-01-05 17:48:40,899-WARNING: consumer failed with error: failed to map consumer[%s], error: 'tuple' object has no attribute 'keys'[consumer[consumer-68e_1] exits]
2020-01-05 17:48:40,899-WARNING: Your reader has raised an exception!
请帮忙查看下什么原因。造成预测数据生成出错,预测数据该如何准备?能否提供一份fastRCNN预测数据生成的案例?