anibali/margipose

Loss values

mshooter opened this issue · 2 comments

Could you tell me if your values are getting negative?
When I use the loss described in your paper I am getting negative values

That should not be possible since each term in equation (6) of the paper is non-negative (l2 loss can't be negative, and JSD is lower-bounded by zero). Make sure that you have a) normalised the heatmaps, and b) implemented JSD correctly. My guess is that the heatmaps have not been normalised (each 2D heatmap should sum to one).

I assume that you are trying to create your own implementation of a MargiPose-like loss function without using this package. These days I suggest using Kornia to assist with this, which provides:

  • spatial_softmax2d - normalises heatmaps, i.e. the last block in Figure 6. Note that you can't just use torch.nn.Softmax2d since that function operates along a different tensor axis.
  • spatial_expectation2d - calculates the expectation of normalised heatmaps. This function can be used to help calculate mu, see equation (3). For more details on how to do this, look at heatmaps_to_coords but replace dsnt with spatial_expectation2d.
  • js_div_loss_2d - calculates JSD between two normalised heatmaps.

Thank you for your suggestions!
I did try not to implement it myself I mostly used the code that was available.
However, I did have to change certain things depending on the dataset.