RotationDetection
RotationDetection copied to clipboard
Test_mlt res output
Hello,
I have a question regarding the "res" in the test_mlt_base.py . The result_queue is initialized with result_queue = Queue(500)
, which to my understanding creates a Queue object with length 500.
Then the res = result_queue.get()
is called and somehow this creates boxes and scales in the res
variable.
I do not really understand, why the res = result_queue.get()
results in me having boxes and scales, that I can draw on an image. Where are the predictions generated?
I would love to hear your explanation to better understand the code. Thank you very much and best regards
def test_mlt(self, det_net, real_test_img_list, txt_name):
save_path = os.path.join('./test_mlt', self.cfgs.VERSION)
tools.makedirs(save_path)
nr_records = len(real_test_img_list)
pbar = tqdm(total=nr_records)
gpu_num = len(self.args.gpus.strip().split(','))
nr_image = math.ceil(nr_records / gpu_num)
result_queue = Queue(500)
procs = []
for i, gpu_id in enumerate(self.args.gpus.strip().split(',')):
start = i * nr_image
end = min(start + nr_image, nr_records)
split_records = real_test_img_list[start:end]
proc = Process(target=self.worker, args=(int(gpu_id), split_records, det_net, result_queue))
print('process:%d, start:%d, end:%d' % (i, start, end))
proc.start()
procs.append(proc)
for i in range(nr_records):
res = result_queue.get()
tools.makedirs(os.path.join(save_path, 'mlt_res'))
if res['boxes'].shape[0] == 0:
fw_txt_dt = open(os.path.join(save_path, 'mlt_res', 'res_{}.txt'.format(
res['image_id'].split('/')[-1].split('.')[0].split('ts_')[1])), 'w')
fw_txt_dt.close()
pbar.update(1)
fw = open(txt_name, 'a+')
fw.write('{}\n'.format(res['image_id'].split('/')[-1]))
fw.close()
continue
x1, y1, x2, y2, x3, y3, x4, y4 = res['boxes'][:, 0], res['boxes'][:, 1], res['boxes'][:, 2], res['boxes'][:, 3],\
res['boxes'][:, 4], res['boxes'][:, 5], res['boxes'][:, 6], res['boxes'][:, 7]
x1, y1 = x1 * res['scales'][0], y1 * res['scales'][1]
x2, y2 = x2 * res['scales'][0], y2 * res['scales'][1]
x3, y3 = x3 * res['scales'][0], y3 * res['scales'][1]
x4, y4 = x4 * res['scales'][0], y4 * res['scales'][1]
boxes = np.transpose(np.stack([x1, y1, x2, y2, x3, y3, x4, y4]))