def csp_process(): try: req = json.loads(request.body.read()) score = req['score'] img = np.array(req['img'], np.uint8) assert (img.shape[0], img.shape[1]) == C.size_test except (TypeError, AssertionError, IndexError): return 'null' x_rcnn = format_img(img, C) Y = model.predict(x_rcnn) if C.offset: boxes = bbox_process.parse_det_offset(Y, C, score=score, down=4) else: boxes = bbox_process.parse_det(Y, C, score=score, down=4, scale=C.scale) boxes[:, [0, 1, 2, 3, 4]] = boxes[:, [1, 0, 3, 2, 4]] return json.dumps(boxes.tolist())
model.load_weights(weight1, by_name=True) res_all = [] start_time = time.time() for f in range(num_imgs): filepath = val_data[f]['filepath'] images_dir_name = 'images{}/'.format(exp_name if 'base' not in exp_name else '') filepath = filepath.replace('images/', images_dir_name) img = cv2.imread(filepath) x_rcnn = format_img(img, C) Y = model.predict(x_rcnn) if C.offset: boxes = bbox_process.parse_det_offset(Y, C, score=0.1, down=4) else: boxes = bbox_process.parse_det(Y, C, score=0.1, down=4, scale=C.scale) if len(boxes) > 0: f_res = np.repeat(f + 1, len(boxes), axis=0).reshape((-1, 1)) boxes[:, [2, 3]] -= boxes[:, [0, 1]] res_all += np.concatenate((f_res, boxes), axis=-1).tolist() np.savetxt(res_file_txt, np.array(res_all), fmt='%6f') print(time.time() - start_time) dt_path = res_path json_path = convert_file(res_file_txt) annFile_test = '/home/vobecant/PhD/CSP/eval_city/val_gt.json' resFile = os.path.join(dt_path, 'val_dt.json') respath = os.path.join(dt_path, 'results_testSet.txt') res_file = open(respath, "w") print('\nResults on the TEST set:')
x_img = cv2.imread(img_data['filepath']) x_img = x_img.astype(np.float32) x_img[:, :, 0] -= C.img_channel_mean[0] x_img[:, :, 1] -= C.img_channel_mean[1] x_img[:, :, 2] -= C.img_channel_mean[2] X.append(np.expand_dims(x_img, axis=0)) X = np.concatenate(X, axis=0) Y = model.predict(X) if C.offset: boxes_batch = bbox_process.parse_det_offset_batch( Y, C_tst, score=0.1, down=4) else: assert False boxes_batch = bbox_process.parse_det(Y, C_tst, score=0.1, down=4, scale=C.scale) if cur_val_id == 0: print( 'Val X shape: {}, Y shape: {}, boxes_batch: {}'.format( X[0].shape, Y[0].shape, boxes_batch)) if len(sys.argv) == 3: assert False, "End of debug..." # boxes are in XYXY format for boxes, fname in zip(boxes_batch, fnames): if len(boxes) > 0: img_id = img_id_lut[fname] f_res = np.repeat(img_id, len(boxes), axis=0).reshape( (-1, 1)) # change boxes to XYWH format