def compute_loss_cycle3(self): P1_P3_P2_cycle = loss.batch_cycle_3(self.P1_P3, self.idx1_P2_P1, self.idx1_P3_P2, self.batchs) P2_P1_P3_cycle = loss.batch_cycle_3(self.P2_P1, self.idx1_P3_P2, self.idx1_P1_P3, self.batchs) self.loss_train_cycleL2_3 = (1 / 6.0) * (loss.L2( P1_P3_P2_cycle, self.P1) + loss.L2(P2_P1_P3_cycle, self.P2))
def compute_loss_selfReconstruction(self, network): rot_matrix = self.rot_matrix.cuda().float().transpose(2, 1).contiguous() P4 = self.P3.bmm(rot_matrix).detach() scale = torch.rand(P4.size(0), 1, 3).cuda() - 0.5 # uniform sampling -0.5, 0.5 P4 = P4 + scale * P4 # Anisotropic scaling P3 = self.P3.transpose(2, 1).contiguous() P4 = P4.transpose(2, 1).contiguous() P4_P3 = network(P3, P4) # forward pass P3_P4 = network(P4, P3) # forward pass self.loss_train_selfReconstruction_L2 = (1 / 2.0) * ( loss.L2(P4_P3, P4) + loss.L2(P3_P4, P3))
def test_iteration(self): self.couple.separate_points_normal_labels() batchs = self.couple.P1.size(0) self.couple.add_P2P1( *loss.forward_chamfer(self.network, self.couple.P1, self.couple.P2, local_fix=self.fix, distChamfer=self.distChamfer)) loss_val_Deformation_ChamferL2 = loss.chamferL2( self.couple.dist1_P2_P1, self.couple.dist2_P2_P1) loss_val_Reconstruction_L2 = loss.L2(self.couple.P2_P1, self.couple.P2) self.log.update("loss_val_Deformation_ChamferL2", loss_val_Deformation_ChamferL2) self.log.update("loss_val_Reconstruction_L2", loss_val_Reconstruction_L2) print('\r' + colored( '[%d: %d/%d]' % (self.epoch, self.iteration, self.len_dataset_test / (self.opt.batch_size)), 'red') + colored( 'loss_val_Deformation_ChamferL2: %f' % loss_val_Deformation_ChamferL2.item(), 'yellow'), end='') if self.iteration % 60 == 1 and self.opt.display: self.visualizer.show_pointclouds(points=self.couple.P2[0], Y=self.couple.label2[0], title="val_B") self.visualizer.show_pointclouds(points=self.couple.P1[0], Y=self.couple.label1[0], title="val_A") self.visualizer.show_pointclouds(points=self.couple.P2_P1[0], Y=self.couple.label1[0], title="val_B_reconstructed") # Compute Miou when labels are tranfered from P1 to P2. predicted_target = self.couple.label1.view(-1)[ self.couple.idx2_P2_P1].view(batchs, -1) for shape in range(batchs): if self.couple.cat_1 == self.couple.cat_2: target = self.couple.label2[shape].squeeze().data.cpu().numpy() iou_val = miou_shape.miou_shape( predicted_target[shape].squeeze().cpu().numpy(), target, self.dataset_train.part_category[self.couple.cat_1[shape]]) self.log.update("iou_val", iou_val)