This may be trivial, but for me takes long time to solve in Python. I tried to implement multiprocessing and I used pool. I need to pass multiple arguments. Then I implement like
def doWork(worker_args):
bbox_list, conf_list, all_rects, w, h, pix_per_w, n = worker_args
sys.stdout.write("w: %d%% \n" % n )
sys.stdout.flush()
for k in range(h * w):
conf = conf_list[n][k,1].flatten()[0]
if conf > 0.75:
y = int(k / w)
x = int(k % w)
bbox = bbox_list[n][k]
abs_cx = pix_per_w/2 + pix_per_w*x + int(bbox[0,0,0])
abs_cy = pix_per_h/2 + pix_per_h*y+int(bbox[1,0,0])
w = bbox[2,0,0]
h = bbox[3,0,0]
all_rects[y][x].append(Rect(abs_cx,abs_cy,w,h,conf))
Then from main, I sent as
all_rects = [[[] for x in range(net_config["grid_width"])] for y in range(net_config["grid_height"])]
pool = multiprocessing.Pool(len(bbox_list))
worker_args = [(bbox_list, conf_list, all_rects, net_config["grid_width"], net_config["grid_height"], pix_per_w, range(len(bbox_list)))]
pool.map(doWork, worker_args)
Then error in printing n in doWork
function is
TypeError: %d format: a number is required, not list
If I implement like
def doWork(n): and
in main
pool.map(doWork, range(len(bbox_list)))
It works. Send data from 0 to 5.
Then I implement like
def doWork(worker_args): and
in main
worker_args = [(bbox_list, conf_list, all_rects, net_config["grid_width"], net_config["grid_height"], pix_per_w)]
pool.map(doWork, worker_args)
It works also. But if I combine two as in the first example, then I got error at n. How to send n in single digit, not in list? Thanks