def debug(self, batch, output, iter_id): opt = self.opt wh = output['wh'] if opt.reg_bbox else None reg = output['reg'] if opt.reg_offset else None dets = ddd_decode(output['hm'], output['rot'], output['dep'], output['dim'], wh=wh, reg=reg, K=opt.K) # x, y, score, r1-r8, depth, dim1-dim3, cls dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2]) calib = batch['meta']['calib'].detach().numpy() # x, y, score, rot, depth, dim1, dim2, dim3 # if opt.dataset == 'gta': # dets[:, 12:15] /= 3 dets_pred = ddd_post_process( dets.copy(), batch['meta']['c'].detach().numpy(), batch['meta']['s'].detach().numpy(), calib, opt) dets_gt = ddd_post_process( batch['meta']['gt_det'].detach().numpy().copy(), batch['meta']['c'].detach().numpy(), batch['meta']['s'].detach().numpy(), calib, opt) #for i in range(input.size(0)): for i in range(1): debugger = Debugger(dataset=opt.dataset, ipynb=(opt.debug==3), theme=opt.debugger_theme) img = batch['input'][i].detach().cpu().numpy().transpose(1, 2, 0) img = ((img * self.opt.std + self.opt.mean) * 255.).astype(np.uint8) pred = debugger.gen_colormap( output['hm'][i].detach().cpu().numpy()) gt = debugger.gen_colormap(batch['hm'][i].detach().cpu().numpy()) debugger.add_blend_img(img, pred, 'hm_pred') debugger.add_blend_img(img, gt, 'hm_gt') # decode debugger.add_ct_detection( img, dets[i], show_box=opt.reg_bbox, center_thresh=opt.center_thresh, img_id='det_pred') debugger.add_ct_detection( img, batch['meta']['gt_det'][i].cpu().numpy().copy(), show_box=opt.reg_bbox, img_id='det_gt') debugger.add_3d_detection( batch['meta']['image_path'][i], dets_pred[i], calib[i], center_thresh=opt.center_thresh, img_id='add_pred') debugger.add_3d_detection( batch['meta']['image_path'][i], dets_gt[i], calib[i], center_thresh=opt.center_thresh, img_id='add_gt') # debugger.add_bird_view( # dets_pred[i], center_thresh=opt.center_thresh, img_id='bird_pred') # debugger.add_bird_view(dets_gt[i], img_id='bird_gt') debugger.add_bird_views( dets_pred[i], dets_gt[i], center_thresh=opt.center_thresh, img_id='bird_pred_gt') # debugger.add_blend_img(img, pred, 'out', white=True) debugger.compose_vis_add( batch['meta']['image_path'][i], dets_pred[i], calib[i], opt.center_thresh, pred, 'bird_pred_gt', img_id='out') # debugger.add_img(img, img_id='out') if opt.debug ==4: debugger.save_all_imgs(opt.debug_dir, prefix='{}'.format(iter_id)) else: debugger.show_all_imgs(pause=True)
def save_result(self, output, batch, results): opt = self.opt wh = output['wh'] if opt.reg_bbox else None reg = output['reg'] if opt.reg_offset else None dets = ddd_decode(output['hm'], output['rot'], output['dep'], output['dim'], wh=wh, reg=reg, K=opt.K) # x, y, score, r1-r8, depth, dim1-dim3, cls dets = dets.detach().cpu().numpy().reshape(1, -1, dets.shape[2]) calib = batch['meta']['calib'].detach().numpy() # x, y, score, rot, depth, dim1, dim2, dim3 dets_pred = ddd_post_process(dets.copy(), batch['meta']['c'].detach().numpy(), batch['meta']['s'].detach().numpy(), calib, opt) img_id = batch['meta']['img_id'].detach().numpy()[0] results[img_id] = dets_pred[0] for j in range(1, opt.num_classes + 1): keep_inds = (results[img_id][j][:, -1] > opt.center_thresh) results[img_id][j] = results[img_id][j][keep_inds]
def process(self, images, return_time=False): with torch.no_grad(): torch.cuda.synchronize() output = self.model(images)[-1] output['hm'] = output['hm'].sigmoid_() # print(output['hm'][:,:,65:71,168:174]) # print("--------------------------------") output['dep'] = 1. / (output['dep'].sigmoid() + 1e-6) - 1. # print( output['dep'][:,:,68,171]) # print("---------------------------------------") wh = output['wh'] if self.opt.reg_bbox else None reg = output['reg'] if self.opt.reg_offset else None # print( output['reg'][:,:,68,171]) # assert 0 torch.cuda.synchronize() forward_time = time.time() dets = ddd_decode(output['hm'], output['rot'], output['dep'], output['dim'], wh=wh, reg=reg, K=self.opt.K) if return_time: return output, dets, forward_time else: return output, dets
def process(self, images, return_time=False): with torch.no_grad(): torch.cuda.synchronize() # 字典 output = self.model(images)[-1] # heatmap shape: batchsize x 3 x 96 x 320 output['hm'] = output['hm'].sigmoid_() # dep shape: batchsize x 1 x 96 x 320 output['dep'] = 1. / (output['dep'].sigmoid() + 1e-6) - 1. wh = output['wh'] if self.opt.reg_bbox else None reg = output['reg'] if self.opt.reg_offset else None torch.cuda.synchronize() forward_time = time.time() # rot shape: batchsize x 8 x 96 x 320 # dim shape: batchsize x 3 x 96 x 320 # dets shape: batchsize x K x 18(torch.Tensor) dets = ddd_decode(output['hm'], output['rot'], output['dep'], output['dim'], wh=wh, reg=reg, K=self.opt.K) if return_time: return output, dets, forward_time else: return output, dets
def process(self, images, return_time=False): with torch.no_grad(): torch.cuda.synchronize() output = self.model(images)[-1] output['hm'] = output['hm'].sigmoid_() output['dep'] = 1. / (output['dep'].sigmoid() + 1e-6) - 1. wh = output['wh'] if self.opt.reg_bbox else None reg = output['reg'] if self.opt.reg_offset else None output['vertex_hm'] = output['vertex_hm'].sigmoid_() torch.cuda.synchronize() forward_time = time.time() dets = ddd_decode(output['hm'], output['rot'], output['dep'], output['dim'], output['vertex_coordinate'], output['vertex_hm'], output['vertex_reg_offset'], wh=wh, reg=reg, K=self.opt.K) if return_time: return output, dets, forward_time else: return output, dets
def process(self, images, return_time=False): with torch.no_grad(): torch.cuda.synchronize() output = self.model(images)[-1] print ("xxxxxxxxxxxxxoutputxxxxxxxx\n") for n,t in output.items(): print (n," || ", t.size()) print ("\nxxxxxxxxxxxxxxxxxxxxxxxx\n") output['hm'] = output['hm'].sigmoid_() output['dep'] = 1. / (output['dep'].sigmoid() + 1e-6) - 1. wh = output['wh'] if self.opt.reg_bbox else None print ("reg offset",self.opt.reg_offset) reg = output['reg'] if self.opt.reg_offset else None torch.cuda.synchronize() forward_time = time.time() dets = ddd_decode(output['hm'], output['rot'], output['dep'], output['dim'], wh=wh, reg=reg, K=self.opt.K) if return_time: return output, dets, forward_time else: return output, dets
def process(self, images, return_time=False): with torch.no_grad(): torch.cuda.synchronize() output = self.model(images)[-1] output['hm'] = output['hm'].sigmoid_() #output['dep'] = output['dep'].sigmoid_() output['rot'] = output['rot'].sigmoid_() denominator = torch.rsqrt(output['rot'][:, 0:1, :, :]**2 + output['rot'][:, 0:1, :, :]**2) output['rot'] = output['rot'] * denominator output['dim'] = output['dim'].sigmoid_() - 0.5 #TODO depth_tran,rotation_trans, # print(output['hm'][:,:,65:71,168:174]) # print("--------------------------------") #output['dep'] = np.exp( output['dep']) # print( output['dep'][:,:,68,171]) # print("---------------------------------------") wh = output['wh'] if self.opt.reg_bbox else None reg = output['reg'] if self.opt.reg_offset else None # print( output['reg'][:,:,68,171]) # assert 0 torch.cuda.synchronize() forward_time = time.time() #decocde_smoke dets = ddd_decode(output['hm'], output['rot'], output['dep'], output['dim'], wh=wh, reg=reg, K=self.opt.K) if return_time: return output, dets, forward_time else: return output, dets