Trying to port a matlab model to pytorch

I’m trying to port anilbas/3DMMasSTN model to pytorch suvojit-0x55aa/3DMMasSTN-Pytorch

I tried to implement it as closely to MATLAB code as possible but it seems I can’t train the model.

  • Firstly, original code has a bilinear sampler, I looked into the code and Pytorch’s F.grid_sample looked like had what it was trying to implement, but seems there are differences, cause the pytorch model is generating garbage.
  • Moreover MATLAB uses [0..255] range for its input image, unlike [0..1] for Pytorch, which range should be used for weights converted from matlab to pytorch.
  • The original code sets some weights manually but when I do the same for pytorch, it’s training behaviour is different than MATLAB’s.
  • What are part of the code should I look for differences, since I’m not well versed in MATLAB.

I appreciate anyone taking the time to look into it and giving some pointer so that can I can implement it correctly. Thanks in advance.


in we a have a reimplementation of OpenCV remap which for what you describe I think might be similar assuming your sampling tensor in pixel space.