def forward_2d_losses(self, out_var, target_var): out_xy = out_var.narrow(-1, 0, 2) target_xy = target_var.narrow(-1, 0, 2) losses = ( euclidean_losses(out_xy, target_xy) + self._calculate_pixelwise_loss(self.xy_heatmaps[-1], target_xy)) return losses
def forward_2d_losses(self, out_var, target_var): target_xy = target_var.narrow(-1, 0, 2) losses = 0 for xy_hm, zy_hm, xz_hm in zip(self.xy_heatmaps, self.zy_heatmaps, self.xz_heatmaps): losses += self._calculate_pixelwise_loss(xy_hm, target_xy) losses += euclidean_losses(out_var.narrow(-1, 0, 2), target_xy) return losses
def forward_2d_losses(self, out_var, target_var): target_xy = target_var.narrow(-1, 0, 2) losses = 0 for xy_hm, zy_hm, xz_hm in zip(self.xy_heatmaps, self.zy_heatmaps, self.xz_heatmaps): # Pixelwise heatmap loss. losses += self._calculate_pixelwise_loss(xy_hm, target_xy) # Calculated coordinate loss. actual_xy = self.heatmaps_to_coords(xy_hm, zy_hm, xz_hm)[..., :2] losses += euclidean_losses(actual_xy, target_xy) return losses
def forward_3d_losses(self, out_var, target_var): target_xyz = target_var.narrow(-1, 0, 3) losses = 0 target_xy = target_xyz.narrow(-1, 0, 2) target_zy = torch.cat([target_xyz.narrow(-1, 2, 1), target_xyz.narrow(-1, 1, 1)], -1) target_xz = torch.cat([target_xyz.narrow(-1, 0, 1), target_xyz.narrow(-1, 2, 1)], -1) for xy_hm, zy_hm, xz_hm in zip(self.xy_heatmaps, self.zy_heatmaps, self.xz_heatmaps): losses += self._calculate_pixelwise_loss(xy_hm, target_xy) losses += self._calculate_pixelwise_loss(zy_hm, target_zy) losses += self._calculate_pixelwise_loss(xz_hm, target_xz) losses += euclidean_losses(out_var, target_xyz) return losses
def forward_3d_losses(self, out_var, target_var): out_xyz = out_var.narrow(-1, 0, 3) target_xyz = target_var.narrow(-1, 0, 3) target_xy = target_xyz.narrow(-1, 0, 2) target_zy = torch.cat( [target_xyz.narrow(-1, 2, 1), target_xyz.narrow(-1, 1, 1)], -1) target_xz = torch.cat( [target_xyz.narrow(-1, 0, 1), target_xyz.narrow(-1, 2, 1)], -1) losses = ( euclidean_losses(out_xyz, target_xyz) + self._calculate_pixelwise_loss(self.xy_heatmaps[-1], target_xy) + self._calculate_pixelwise_loss(self.zy_heatmaps[-1], target_zy) + self._calculate_pixelwise_loss(self.xz_heatmaps[-1], target_xz)) return losses
def forward_3d_losses(self, out_var, target_var): target_xyz = target_var.narrow(-1, 0, 3) losses = 0 target_xy = target_xyz.narrow(-1, 0, 2) target_zy = torch.cat( [target_xyz.narrow(-1, 2, 1), target_xyz.narrow(-1, 1, 1)], -1) target_xz = torch.cat( [target_xyz.narrow(-1, 0, 1), target_xyz.narrow(-1, 2, 1)], -1) for xy_hm, zy_hm, xz_hm in zip(self.xy_heatmaps, self.zy_heatmaps, self.xz_heatmaps): # Pixelwise heatmap loss. losses += self._calculate_pixelwise_loss(xy_hm, target_xy) losses += self._calculate_pixelwise_loss(zy_hm, target_zy) losses += self._calculate_pixelwise_loss(xz_hm, target_xz) # Calculated coordinate loss. actual_xyz = self.heatmaps_to_coords(xy_hm, zy_hm, xz_hm) losses += euclidean_losses(actual_xyz, target_xyz) return losses
def mpjpe(actual, expected, included_joints=None): dists = euclidean_losses(actual, expected) if included_joints is not None: dists = dists.gather(-1, torch.LongTensor(included_joints)) return dists.mean().item()
def pck(actual, expected, included_joints=None, threshold=150): dists = euclidean_losses(actual, expected) if included_joints is not None: dists = dists.gather(-1, torch.LongTensor(included_joints)) return (dists < threshold).double().mean().item()