| 40 | return loss_dir |
| 41 | |
| 42 | def compute_loss_dir_l1(gt_hair_strands, pred_hair_strands): |
| 43 | nr_verts_per_strand=256 |
| 44 | |
| 45 | pred_points = pred_hair_strands.view(-1, nr_verts_per_strand, 3) |
| 46 | gt_hair_strands=gt_hair_strands.view(-1, nr_verts_per_strand, 3) |
| 47 | |
| 48 | # get also a loss for the direciton, we need to compute the direction |
| 49 | pred_deltas = compute_dirs(pred_points) |
| 50 | pred_deltas = pred_deltas.view(-1, 3) |
| 51 | pred_deltas = pred_deltas*nr_verts_per_strand #Just because the deltas are very tiny and I want them in a nicer range for the loss |
| 52 | |
| 53 | gt_dir = compute_dirs(gt_hair_strands) |
| 54 | gt_dir = gt_dir.view(-1, 3) |
| 55 | gt_dir = gt_dir*nr_verts_per_strand #Just because the deltas are very tiny and I want them in a nicer range for the loss |
| 56 | # loss_dir = self.cosine_embed_loss(pred_deltas, gt_dir, torch.ones(gt_dir.shape[0]).cuda()) |
| 57 | |
| 58 | loss_l1 = torch.nn.functional.l1_loss(pred_deltas, gt_dir).mean() |
| 59 | return loss_l1 |
| 60 | |
| 61 | def compute_loss_curv_l1(gt_hair_strands, pred_hair_strands): |
| 62 | nr_verts_per_strand=256 |