Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misalignment with TensorFlow weights #58

Open
ncherel opened this issue Jun 1, 2021 · 3 comments
Open

Misalignment with TensorFlow weights #58

ncherel opened this issue Jun 1, 2021 · 3 comments

Comments

@ncherel
Copy link

ncherel commented Jun 1, 2021

Hello,
First of all, thank you for your great work.

I have observed a strange problem when using the converted weights from TensorFlow (thanks again!).
I do not get exactly the same results than the official implementation. They are very close but slightly misaligned:
output

The coarse network seems to do its job correctly but something happens during the refinement step.
Do you have an idea of where it could come from ?

Tested with PyTorch 1.7 and TensorFlow 1.15

@daa233
Copy link
Owner

daa233 commented Jun 1, 2021

@ncherel Thansk for your attention!

I just confirmed that there is a mislalignment for the output. Thanks for pointing out it happens in the refined stage.

The resullt of examples/imagenet/imagenet_patches_ILSVRC2012_val_00025892_input.png by the converted TF model:
image

Sorry, I am not sure about the reason for this problem and have little time to find it recently.

Here are some possible reasons:

  • Different conv padding (or other parameters) misalignment between TF and PyTorch.
  • Different implementation details in the contextual attention module between TF and PyTorch.

By the way, the TF model is converted by @zphang semi-manually in this pr, you may try to convert it by yourself and check it again.

@ncherel
Copy link
Author

ncherel commented Jun 4, 2021

Thanks for your input. I finally managed to reproduce the official results using your code.
I had to change a few things :

  • convert input image from RGB to BGR
  • add a same_padding operation before the conv_downsample and slightly modify the function. When the total padding is odd, your code will insert 1 more for left / top rather than right / bottom as TF
  • last, Pytorch interpolate can't align corners when using nearest neighbors. Switching off corners alignment in TF gives the same result as this PyTorch code. Maybe one day PyTorch will support this and everything will be 1:1 equivalent.

@daa233
Copy link
Owner

daa233 commented Jun 5, 2021

Awesome! Could you please share your code in a branch/pull request so that other people may learn from it? Thanks for your excellent work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants