pytorch
a8ea4178 - Fixed bug in interpolate when interpolation size is larger than max (#101403)

Commit
2 years ago
Fixed bug in interpolate when interpolation size is larger than max (#101403) ## Description This is a bug fix for rare cases that can happen with specific scale, antialias=False, output for a random line can be wrong. For example: ``` line 14 output uint8: [76, 78, 80, 81, 83, 85, 87, 88, 90] expected float: [149, 152, 155, 158, 161, 164, 167, 170, 173] diff: [-73, -74, -75, -77, -78, -79, -80, -82, -83] opencv ref: [149 152 155 158 161 164 167 170 173] ``` It appears that for this line we have 3 weights coeff instead of 2: ``` line 13 | 351, 2 k: 1130 15254 line 14 | 378, 3 k: 0 16384 -6780 <------- We should have 2 weights and not 3 line 15 | 432, 2 k: 15254 1130 ``` which comes from our `_compute_weights_aa` function that is specifically used for AA=False and uint8. ``` xmin = std::max( static_cast<int64_t>(center - support + 0.5 + align_corners_delta), static_cast<int64_t>(0)); xsize = std::min( static_cast<int64_t>(center + support + 0.5 + align_corners_delta), input_size) - xmin; ``` ``` center - support + 0.5 + align_corners_delta: 14.999999999999998 static_cast<int64_t>(center - support + 0.5 + align_corners_delta): 14 xmin -> 14 center + support + 0.5 + align_corners_delta: 17.0 static_cast<int64_t>(center + support + 0.5 + align_corners_delta): 17.0 xsize -> 17 - 14 = 3 <------ 3 instead of 2 ``` For float dtype, AA=False weights and indices are computed differently due to historically first implemented. In any case, `xsize` should not be larger than `max_interp_size`, so we decided to clip `xsize`. Once fixed computed indices and weights are same as for float dtype code path: ``` # Option: xsize = min(xsize, max_interp_size) Line Num | xmin, xsize 14 | 378, 2 xmin=378 <---> xmin = i * stride = i * 3 * 9 => i = 14 k: 0 16384 16384 = w * (1 << 14) => w = 1.0 => i=14, w=0 and i=15, w=1 ``` vs ``` Line Num | index0, index1 F32: 14 | 15, 16 F32: lambda0, lambda1: 0.999999, 9.53674e-07 ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/101403 Approved by: https://github.com/NicolasHug
Author
Committer
Parents
Loading