here is approximately what I did:
import mxnet as mx
import cv2
from multiprocessing import Pool
from itertools import repeat
num_worker=4
CNNNet=[]
img = cv2.imread('../datasets/1.jpg')
sym, arg_params, aux_params = mx.model.load_checkpoint('det1', 0)
for i in range(num_worker):
worker_net = mx.mod.Module(symbol=sym,label_names=None)
worker_net.bind(data_shapes=[('data', (1, 3, 1000, 1000))],for_training=False)
worker_net.set_params(arg_params,aux_params)
CNNNet.append(worker_net)
pool = Pool(num_worker)
threshold = 0.6
res = pool.map(do_work_warpper,zip(repeat(img),CNNNet[:num_worker],repeat(threshold)))
and the do_work_warpper()
function is:
def do_work_warpper(args):
return do_work(*args)
def do_work(img,net,threshold):
#do image predict job here
return res
I am puzzled by the question that when using multiprocessing.Pool
with the mx.mod.Module
object, I get the error in python3.6:
TypeError: can't pickle module objects
or in python2.7:
PicklingError: Can't pickle <type 'module'>: attribute lookup __builtin__.module failed
any suggestion will be appreciated.