def post_process(self, dets, meta, scale=1): dets = dets.detach().cpu().numpy() dets = dets.reshape(1, -1, dets.shape[2]) dets = ctdet_post_process( dets.copy(), [meta['c']], [meta['s']], meta['out_height'], meta['out_width']) return dets
def post_process(self, dets, meta): dets = dets.reshape(1, -1, dets.shape[-1]) dets = ctdet_post_process(dets.copy(), [meta['c']], [meta['s']], meta['out_height'], meta['out_width'], self.opt.num_classes) for j in range(1, self.opt.num_classes + 1): dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) return dets[0]
def post_process(dets, meta): dets = dets.detach().cpu().numpy() dets = dets.reshape(1, -1, dets.shape[2]) dets = ctdet_post_process(dets.copy(), [meta['c']], [meta['s']],meta['out_height'], meta['out_width'], num_classes) for j in range(1, num_classes + 1): dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) #print('dets',dets[0].keys()) return dets[0]
def post_process(self, dets, meta): # 是将在feature上的预测结果,映射到原始图像中,给出在原始图像中128个检测框的坐标、及相应置信度 dets = dets.detach().cpu().numpy() dets = dets.reshape(1, -1, dets.shape[2]) dets = ctdet_post_process( dets.copy(), [meta['c']], [meta['s']], meta['out_height'], meta['out_width'], self.opt.num_classes) for j in range(1, self.opt.num_classes + 1): dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) return dets[0] # dets ::= list, dets[0] ::= dict, key值是1,value维度为128*5
def post_process(self, dets, meta, scale=1): dets = dets.detach().cpu().numpy() dets = dets.reshape(1, -1, dets.shape[2]) dets = ctdet_post_process(dets.copy(), [meta['c']], [meta['s']], meta['out_height'], meta['out_width'], self.opt.num_classes) for j in range(1, self.num_classes + 1): dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) dets[0][j][:, :4] /= scale return dets[0]
def post_process(self, dets, meta): """ change detection coordinate based on original image size """ dets = dets.reshape(1, -1, dets.shape[-1]) dets = ctdet_post_process(dets.copy(), [meta['c']], [meta['s']], meta['out_height'], meta['out_width'], self.opt.num_classes) for j in range(1, self.opt.num_classes + 1): dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) return dets[0]
def save_result(self, output, batch, results): reg = output['reg'] if self.opt.reg_offset else None dets = ctdet_decode( output['hm'], output['wh'], reg=reg, cat_spec_wh=self.opt.cat_spec_wh, K=self.opt.K) dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2]) dets_out = ctdet_post_process( dets.copy(), batch['meta']['c'].cpu().numpy(), batch['meta']['s'].cpu().numpy(), output['hm'].shape[2], output['hm'].shape[3], output['hm'].shape[1]) results[batch['meta']['img_id'].cpu().numpy()[0]] = dets_out[0]
def post_process(self, dets, meta, scale=1): dets = dets.detach().cpu().numpy() dets = dets.reshape(1, -1, dets.shape[2]) # dets 是一个 list, 每一个元素表示一个 batch item 上的 det, # det 是一个 dict, key 是 class_id, 从 1 开始, value 是 (n, 5) 的 array, 前 4 个元素表示坐标, 最后一位表示 score dets = ctdet_post_process(dets.copy(), [meta['c']], [meta['s']], meta['out_height'], meta['out_width'], self.opt.num_classes) for j in range(1, self.num_classes + 1): dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) dets[0][j][:, :4] /= scale return dets[0]
def post_process(self, dets, meta, scale=1): """ recover result to ori img size with meta """ dets = dets.detach().cpu().numpy() # [B,K,6] box,score,cls dets = dets.reshape(1, -1, dets.shape[2]) # [1,B*K,6] dets = ctdet_post_process( # affine transform dets.copy(), [meta['c']], [meta['s']], meta['out_height'], meta['out_width'], self.opt.num_classes) for j in range(1, self.num_classes + 1): dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) dets[0][j][:, :4] /= scale return dets[0]
def post_process(self, dets, meta, scale=1, fpn_stride=1): dets = dets.detach().cpu().numpy() dets = dets.reshape(1, -1, dets.shape[2]) dets = ctdet_post_process( dets.copy(), [meta['c']], [meta['s']], meta['out_height'] / fpn_stride, meta['out_width'] / fpn_stride, self.opt.num_classes) if self.opt.dataset == 'dota': coor_len = 8 else: coor_len = 4 for j in range(1, self.num_classes + 1): dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, coor_len + 1) dets[0][j][:, :coor_len] /= scale return dets[0]
def post_process(opt, dets, meta): dets = dets.detach().cpu().numpy() dets = dets.reshape(1, -1, dets.shape[2]) dets = ctdet_post_process( dets.copy(), [meta["c"]], [meta["s"]], meta["out_height"], meta["out_width"], opt.num_classes, ) for j in range(1, opt.num_classes + 1): dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) return dets[0]
def save_result(self, output, batch, results): reg = output['reg'] if self.opt.reg_offset else None dets = ctdet_decode( output['hm'], output['wh'], reg=reg, cat_spec_wh=self.opt.cat_spec_wh, K=self.opt.K) dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2]) dets_out = ctdet_post_process( dets.copy(), batch['meta']['c'].cpu().numpy(), batch['meta']['s'].cpu().numpy(), output['hm'].shape[2], output['hm'].shape[3], output['hm'].shape[1]) results[batch['meta']['img_id'].cpu().numpy()[0]] = dets_out[0] if self.opt.dataset == 'bdd' or self.opt.dataset == 'bddstream': if 'map_img_id' not in results: results['map_img_id'] = {} results['map_img_id'][batch['meta']['img_id'].cpu().numpy()[0]] = batch['meta']['file_name']
def post_process(self, dets, meta, scale=1): torch.cuda.synchronize() s1 = time.time() dets = dets.cpu().numpy() dets = dets.reshape(1, -1, dets.shape[2]) dets = ctdet_post_process(dets, [meta['c']], [meta['s']], meta['out_height'], meta['out_width'], self.num_classes) for j in range(1, self.num_classes + 1): dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) dets[0][j][:, :4] /= scale torch.cuda.synchronize() s2 = time.time() print("post_process:", s2 - s1) return dets[0]
def post_process(self, dets, meta, scale=1): dets = dets.detach().cpu().numpy() dets = dets.reshape(1, -1, dets.shape[2]) dets = ctdet_post_process(dets.copy(), [meta['c']], [meta['s']], meta['out_height'], meta['out_width'], self.opt.num_classes) for j in range(1, self.num_classes + 1): l = 5 if self.opt.mdn: l += 10 if self.opt.flip_test else 8 dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, l) dets[0][j][:, :4] /= scale if self.opt.mdn: if self.opt.flip_test: dets[0][j][:, 9:15] /= scale else: dets[0][j][:, 7:13] /= scale return dets[0]
def save_result(self, output, batch, results): reg = output["reg"] if self.opt.reg_offset else None dets = mot_decode( output["hm"], output["wh"], reg=reg, cat_spec_wh=self.opt.cat_spec_wh, K=self.opt.K, ) dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2]) dets_out = ctdet_post_process( dets.copy(), batch["meta"]["c"].cpu().numpy(), batch["meta"]["s"].cpu().numpy(), output["hm"].shape[2], output["hm"].shape[3], output["hm"].shape[1], ) results[batch["meta"]["img_id"].cpu().numpy()[0]] = dets_out[0]
def save_result(self, output, batch, results): reg = output['reg'] if self.opt.reg_offset else None dets = ctdet_decode(output['hm'], output['wh'], reg=reg, cat_spec_wh=self.opt.cat_spec_wh, K=1) dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2]) dets_out = ctdet_post_process(dets.copy(), batch['meta']['c'].cpu().numpy(), batch['meta']['s'].cpu().numpy(), output['hm'].shape[2], output['hm'].shape[3], output['hm'].shape[1]) # batch * class * top_K -> dets_out[0][1][0] # results[batch['meta']['img_id'].cpu().numpy()[0]] = dets_out[0][1][0] #print(dets[0]) results.append({ 'predict': dets[0][0][0:4], 'gt_bbox': batch['meta']['gt_det'][0][0][0:4].tolist() })
def save_result(self, output, batch, results): opt = self.opt if opt.task == 'ctdet': reg = output['reg'] if self.opt.reg_offset else None dets = ctdet_decode(output['hm'], output['wh'], reg=reg, cat_spec_wh=self.opt.cat_spec_wh, K=self.opt.K) dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2]) dets_out = ctdet_post_process(dets.copy(), batch['meta']['c'].cpu().numpy(), batch['meta']['s'].cpu().numpy(), output['hm'].shape[2], output['hm'].shape[3], output['hm'].shape[1]) results[batch['meta']['img_id'].cpu().numpy()[0]] = dets_out[0] elif opt.task == 'multi_pose': reg = output['reg'] if self.opt.reg_offset else None hm_hp = output['hm_hp'] if self.opt.hm_hp else None hp_offset = output['hp_offset'] if self.opt.reg_hp_offset else None dets = multi_pose_decode(output['hm'], output['wh'], output['hps'], reg=reg, hm_hp=hm_hp, hp_offset=hp_offset, K=self.opt.K) dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2]) dets_out = multi_pose_post_process( dets.copy(), batch['meta']['c'].cpu().numpy(), batch['meta']['s'].cpu().numpy(), output['hm'].shape[2], output['hm'].shape[3]) results[batch['meta']['img_id'].cpu().numpy()[0]] = dets_out[0] else: assert 0, 'task not defined!'
def post_process(self, dets_act, meta, scale=1): dets_act = dets_act.detach().cpu().numpy() dets_act = dets_act.reshape(1, -1, dets_act.shape[2]) dets_act = ctdet_post_process(dets_act.copy(), [meta['c']], [meta['s']], meta['out_height'], meta['out_width'], self.opt.num_obj_classes, self.opt.num_act_classes) # print(dets_act) # for j in range(1, self.num_obj_classes + 1): # dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5) # dets[0][j][:, :4] /= scale for j in range(1, self.num_act_classes + 1): dets_act[0][j] = np.array(dets_act[0][j], dtype=np.float32).reshape(-1, 7) dets_act[0][j][:, :6] /= scale # print(dets_act[0]) return dets_act[0]