sniklaus / pytorch-pwc

a reimplementation of PWC-Net in PyTorch that matches the official Caffe version
GNU General Public License v3.0
620 stars 123 forks source link

Normalization in `backward` function. #66

Closed Jiahao-Ma closed 7 months ago

Jiahao-Ma commented 7 months ago

The line of code highlighted in the red bounding box is what I am confused about. The line is for normalization before the interpolation operation. The normalization normally ranges from -1 to 1 in the torch.nn.functional.grid_sample. But the normalization seems to range from 0 to 2. image

sniklaus commented 7 months ago

Consider a flow that is -100 pixels along the X axis and an image with a width of 200 pixels. The grid sampler expects values in the range of -1 to 1 and spans a distance of 200 pixels along the X axis. Conversely, we need to map the -100 px from the flow-domain to -1 units in the grid_sampler-domain. This comes out to dividing the flow by half of the image size, and 1/(0.5*x) is equivalent to 2/x (what is used in the code).