首页 > 解决方案 > 如何将图像批次作为本地人传递给 profile.runctx?

问题描述

我想向profile.runctx Ex发送一批图像

profile.runctx('print (inference(image_batch,batch_size)); print()',
               globals(),
               {'image_batch':'how to send image batch?','batch_size':128})

我有一个函数inference,它接受一个序列图像批次作为输入。如何将一系列图像作为参数传递profile.runctx

标签: pythonunit-testingprofilingfaster-rcnn

解决方案


您在问题中的示例代码中遗漏了许多细节,但这是一个猜测:

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})

推荐阅读