【问题标题】:How to pass image batches as locals to profile.runctx?如何将图像批次作为本地人传递给 profile.runctx?
【发布时间】:2019-09-13 22:32:14
【问题描述】:
我想发一批图片到profile.runctxEx
profile.runctx('print (inference(image_batch,batch_size)); print()',
globals(),
{'image_batch':'how to send image batch?','batch_size':128})
我有一个名为inference 的函数,它接受一个序列图像批次作为输入。如何在profile.runctx 中将图像序列作为参数传递?
【问题讨论】:
标签:
python
unit-testing
profiling
faster-rcnn
【解决方案1】:
您在问题中的示例代码中遗漏了许多细节,但这是一个猜测:
import profile
def inference(image_batches, size):
for i in range(size):
print('image_batches[{}]: {}'.format(i, image_batches[i]))
return 42
image_batch = ['image1', 'image2']
batch_size = 2
profile.runctx('print(inference(image_batch, batch_size)); print()',
globals(), locals())
或者你可以做一些更明确的事情:
profile.runctx('print(inference(image_batch, batch_size)); print()',
globals(), {'image_batch': ['image1', 'image2'],
'batch_size': 2})