def forward(self, outputs, targets_inds, targets_center, targets_2d_wh, targets_2d_offset, targets_2d_wh_mask, targets_poserel, targets_poserel_mask, targets_posemap, targets_posemap_offset, targets_posemap_ind, targets_posemap_mask): opt = self.opt hm_loss, wh_loss, off_loss = 0, 0, 0 hp_loss, off_loss, hm_hp_loss, hp_offset_loss = 0, 0, 0, 0 for s in range(opt.num_stacks): if opt.num_stacks == 1: output = outputs # In symbolic mode, while loading json file, outputs = [a] will become outputs = a else: output = outputs[s] # 0: hm, 1: wh, 2: hps, 3: reg, 4: hm_hp, 5:hp_offset output[0] = _sigmoid(output[0]) if opt.hm_hp and not opt.mse_loss: output[4] = _sigmoid(output[4]) hm_loss = hm_loss + self.crit(output[0], targets_center) / opt.num_stacks hp_loss = hp_loss + self.crit_kp(output[2], targets_poserel_mask, targets_inds, targets_poserel) / opt.num_stacks if opt.wh_weight > 0: wh_loss = wh_loss + self.crit_reg( output[1], targets_2d_wh_mask, targets_inds, targets_2d_wh) / opt.num_stacks if opt.reg_offset and opt.off_weight > 0: off_loss = off_loss + self.crit_reg( output[3], targets_2d_wh_mask, targets_inds, targets_2d_offset) / opt.num_stacks if opt.reg_hp_offset and opt.off_weight > 0: hp_offset_loss = hp_offset_loss + self.crit_reg( output[5], targets_posemap_mask, targets_posemap_ind, targets_posemap_offset) / opt.num_stacks if opt.hm_hp and opt.hm_hp_weight > 0: hm_hp_loss = hm_hp_loss + self.crit_hm_hp( output[4], targets_posemap) / opt.num_stacks loss = opt.hm_weight * hm_loss + opt.wh_weight * wh_loss + \ opt.off_weight * off_loss + opt.hp_weight * hp_loss + \ opt.hm_hp_weight * hm_hp_loss + opt.off_weight * hp_offset_loss #loss_stats = {'loss': loss, 'hm_loss': hm_loss, 'hp_loss': hp_loss, #'hm_hp_loss': hm_hp_loss, 'hp_offset_loss': hp_offset_loss, #'wh_loss': wh_loss, 'off_loss': off_loss} return loss
def forward(self, outputs, targets_inds, targets_center, targets_2d_wh, targets_2d_offset, targets_2d_wh_mask, targets_poserel, targets_poserel_mask, targets_posemap, targets_posemap_offset, targets_posemap_ind, targets_posemap_mask): opt = self.opt hm_loss, wh_loss, off_loss = 0, 0, 0 hp_loss, off_loss, hm_hp_loss, hp_offset_loss = 0, 0, 0, 0 for s in range(opt.num_stacks): output = outputs[s] output['hm'] = _sigmoid(output['hm']) if opt.hm_hp and not opt.mse_loss: output['hm_hp'] = _sigmoid(output['hm_hp']) hm_loss = hm_loss + self.crit(output['hm'], targets_center) / opt.num_stacks hp_loss = hp_loss + self.crit_kp( output['hps'], targets_poserel_mask, targets_inds, targets_poserel) / opt.num_stacks if opt.wh_weight > 0: wh_loss = wh_loss + self.crit_reg( output['wh'], targets_2d_wh_mask, targets_inds, targets_2d_wh) / opt.num_stacks if opt.reg_offset and opt.off_weight > 0: off_loss = off_loss + self.crit_reg( output['reg'], targets_2d_wh_mask, targets_inds, targets_2d_offset) / opt.num_stacks if opt.reg_hp_offset and opt.off_weight > 0: hp_offset_loss = hp_offset_loss + self.crit_reg( output['hp_offset'], targets_posemap_mask, targets_posemap_ind, targets_posemap_offset) / opt.num_stacks if opt.hm_hp and opt.hm_hp_weight > 0: hm_hp_loss = hm_hp_loss + self.crit_hm_hp( output['hm_hp'], targets_posemap) / opt.num_stacks loss = opt.hm_weight * hm_loss + opt.wh_weight * wh_loss + \ opt.off_weight * off_loss + opt.hp_weight * hp_loss + \ opt.hm_hp_weight * hm_hp_loss + opt.off_weight * hp_offset_loss #loss_stats = {'loss': loss, 'hm_loss': hm_loss, 'hp_loss': hp_loss, #'hm_hp_loss': hm_hp_loss, 'hp_offset_loss': hp_offset_loss, #'wh_loss': wh_loss, 'off_loss': off_loss} return loss
def forward(self, outputs, \ targets_center, targets_2d_wh, targets_2d_offset, \ targets_3d_depth, targets_3d_dim, targets_3d_rotbin, targets_3d_rotres, \ targets_inds, targets_2d_wh_mask, targets_3d_rot_mask): opt = self.opt hm_loss, dep_loss, rot_loss, dim_loss = 0, 0, 0, 0 wh_loss, off_loss = 0, 0 for s in range(opt.num_stacks): output = outputs[s] output['hm'] = _sigmoid(output['hm']) output['dep'] = 1. / (output['dep'].sigmoid() + 1e-6) - 1. if opt.eval_oracle_dep: output['dep'] = nd.array( gen_oracle_map(targets_3d_depth.asnumpy(), targets_inds.asnumpy(), opt.output_w, opt.output_h)).as_in_context(opt.device) hm_loss = hm_loss + self.crit(output['hm'], targets_center) / opt.num_stacks if opt.dep_weight > 0: dep_loss = dep_loss + self.crit_reg( output['dep'], targets_2d_wh_mask, targets_inds, targets_3d_depth) / opt.num_stacks if opt.dim_weight > 0: dim_loss = dim_loss + self.crit_reg( output['dim'], targets_2d_wh_mask, targets_inds, targets_3d_dim) / opt.num_stacks if opt.rot_weight > 0: rot_loss = rot_loss + self.crit_rot( output['rot'], targets_3d_rot_mask, targets_inds, targets_3d_rotbin, targets_3d_rotres) / opt.num_stacks if opt.reg_bbox and opt.wh_weight > 0: wh_loss = wh_loss + self.crit_reg( output['wh'], targets_3d_rot_mask, targets_inds, targets_2d_wh) / opt.num_stacks if opt.reg_offset and opt.off_weight > 0: off_loss = off_loss + self.crit_reg( output['reg'], targets_3d_rot_mask, targets_inds, targets_2d_offset) / opt.num_stacks loss = opt.hm_weight * hm_loss + opt.dep_weight * dep_loss + \ opt.dim_weight * dim_loss + opt.rot_weight * rot_loss + \ opt.wh_weight * wh_loss + opt.off_weight * off_loss #print("hm_loss: {}, dep_loss: {}, dim_loss: {}, rot_loss: {}, wh_loss: {}, off_loss: {}".format(hm_loss, dep_loss, dim_loss, rot_loss, wh_loss, off_loss)) #loss_stats = {'loss': loss, 'hm_loss': hm_loss, 'dep_loss': dep_loss, # 'dim_loss': dim_loss, 'rot_loss': rot_loss, # 'wh_loss': wh_loss, 'off_loss': off_loss} return loss
def forward(self, outputs, targets_heatmaps, targets_scale, targets_offset, targets_inds, targets_reg_mask): opt = self.opt hm_loss, wh_loss, off_loss = 0, 0, 0 for s in range(opt.num_stacks): output = outputs[s] if not opt.mse_loss: output['hm'] = _sigmoid(output['hm']) # Optional: Use ground truth for validation if opt.eval_oracle_hm: output['hm'] = targets_heatmaps if opt.eval_oracle_wh: output['wh'] = nd.from_numpy( gen_oracle_map(targets_scale.asnumpy(), targets_inds.asnumpy(), output['wh'].shape[3], output['wh'].shape[2])).as_in_context( opt.device) if opt.eval_oracle_offset: output['reg'] = nd.from_numpy( gen_oracle_map(targets_offset.asnumpy(), targets_inds.asnumpy(), output['reg'].shape[3], output['reg'].shape[2])).as_in_context( opt.device) # 1. heatmap loss hm_loss = hm_loss + self.crit(output['hm'], targets_heatmaps) / opt.num_stacks # 2. scale loss if opt.wh_weight > 0: wh_loss = wh_loss + self.crit_reg( output['wh'], targets_reg_mask, targets_inds, targets_scale) / opt.num_stacks # 3. offset loss if opt.reg_offset and opt.off_weight > 0: off_loss = off_loss + self.crit_reg( output['reg'], targets_reg_mask, targets_inds, targets_offset) / opt.num_stacks # total loss loss = opt.hm_weight * hm_loss + opt.wh_weight * wh_loss + \ opt.off_weight * off_loss loss_stats = { 'loss': loss, 'hm_loss': hm_loss, 'wh_loss': wh_loss, 'off_loss': off_loss } return loss