def detec_hum(self, image): # arg: numpy array with shape of (, , 3) # resize the image manually to the fixed model input size # shape_orig = image.shape image = cv2.resize(image, (self.C.size_test[1], self.C.size_test[0])) x_rcnn = format_img(image, self.C) Y = self.model.predict(x_rcnn) boxes = bbox_process.parse_det_offset(Y, self.C, score=0.1,down=4) return boxes[boxes[:, 4]>0.3] if len(boxes)>0 else []
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())
print('load weights from {}'.format(weight1)) 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')