Hi Shubham!



 towardsautonomy:

In essence, one need to multiply the indices with the pixel value and then take mean of it all.


Yes, this is correct.  More precisely, you need to take the
pixel-value-weighted mean of the pixel locations (indices)
to get the “center-of-mass” location.


But I can’t think of a differentiable way of obtaining indices.


You don’t need to get “differentiable” indices.  What matters is that
your (pre-thresholding) pixel values are differentiable (with respect
to your network weights), and presumably they are.  Your indices
(pixel locations) are fixed constants.  They do not need to be – and
are not – differentiable.
Best.
K. Frank