AliaksandrSiarohin / monkey-net

Animating Arbitrary Objects via Deep Motion Transfer
467 stars 81 forks source link

Suggestions for better numerical stability #13

Closed hubert0527 closed 5 years ago

hubert0527 commented 5 years ago

Hi,

Thanks for open-sourcing the code, really benefits my research a lot!

I found two small problems in the code that may cause numerical instability:

  1. Didn't guarantee s1 - s2 is positive before sqrt: https://github.com/AliaksandrSiarohin/monkey-net/blob/7c116b6591e45421f78d3ecdbc224445ada4ac63/modules/util.py#L254

  2. The singular value can sometimes become too small, causing the output explodes to inf. Adding an epsilon to the denominator can help to stabilize it: https://github.com/AliaksandrSiarohin/monkey-net/blob/7c116b6591e45421f78d3ecdbc224445ada4ac63/modules/keypoint_detector.py#L65

AliaksandrSiarohin commented 5 years ago

Hi, thank you for your suggestion. I also think about this. I believe that adding epsilon to the denomitar may not be appropriate since this epsilon can be order of magnitude higher than the value itself. Instead I tried to add epsilon to a heatmap:

https://github.com/AliaksandrSiarohin/monkey-net/blob/7c116b6591e45421f78d3ecdbc224445ada4ac63/modules/keypoint_detector.py#L49

Which should potentially aliviete the issue of zero singular value, if this is not the case you can try to increase the epsilon.

In any case I found this variances problematic to work with and in follow up work, I eliminate them completely.

hubert0527 commented 5 years ago

Hi,

Thanks for your response!

In any case I found this variances problematic to work with and in follow up work, I eliminate them completely.

Do you mean you only model the mean of the keypoints in this case?

AliaksandrSiarohin commented 5 years ago

Not only the mean. I also estimate affine transformation matrix near each keypoint.

hubert0527 commented 5 years ago

I see, thanks for your suggestions :)