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

Dubious implementation of ROIAlign in 'max' mode #6146

Open
yury-intel opened this issue Dec 16, 2020 · 7 comments
Open

Dubious implementation of ROIAlign in 'max' mode #6146

yury-intel opened this issue Dec 16, 2020 · 7 comments
Labels
contributions welcome lower priority issues for the core ORT teams core runtime issues related to core runtime

Comments

@yury-intel
Copy link

yury-intel commented Dec 16, 2020

There are cases, when the results of ROIAlign may be significally different from expected.

Implementation of ROIAlign runs questionably in MAX mode.


I.e., when weighed data feature_map is collected, we commit MAX - operation to all collected data.
So, we return one of weighed value (by [0, 1] - coefficient), which is assuredly less, then all interpolated values.
In the case of centered coordinates of sampling point, nearly 1/4 from expected value is returned.
We need instead, at first, commit interpolation, and afterwards given type of operation (AVG or MAX).
Suggested algorithm is similar to Caffe implementation.

image
image

@harshithapv harshithapv added core runtime issues related to core runtime type:support labels Dec 16, 2020
@pranavsharma
Copy link
Contributor

Would you like to contribute?

@pranavsharma pranavsharma added the contributions welcome lower priority issues for the core ORT teams label Feb 10, 2021
@fdwr
Copy link
Contributor

fdwr commented Mar 6, 2021

@yury-intel: I found some alignment issues too (comparing against PyTorch, the Mask RCNN paper, and FB research's Detectron 2). Might be the same cause, a half pixel off? #6921

@hariharans29
Copy link
Member

Not quite following this. Can you quantify "running questionably" with a simple test case ? For a given input, what do you expect to see vs what actually gets produced ?

@fdwr
Copy link
Contributor

fdwr commented Apr 16, 2021

@yury-intel : I found a bug in max mode too after running our WindowsAI ONNX conformance tests, which will probably fix your issue too:
https://github.com/microsoft/onnxruntime/pull/7354/files#diff-5498c6fd67f5974ca5cb7692c44c9d881ce74cc59a8d1109bb9b7bd33941ef3aR212

This:

                  T val = std::max(
                      std::max(std::max(pc.w1 * offset_bottom_data[pc.pos1], pc.w2 * offset_bottom_data[pc.pos2]),
                               pc.w3 * offset_bottom_data[pc.pos3]),
                      pc.w4 * offset_bottom_data[pc.pos4]);

Should be:

                  T val = pc.w1 * offset_bottom_data[pc.pos1] + pc.w2 * offset_bottom_data[pc.pos2] +
                          pc.w3 * offset_bottom_data[pc.pos3] + pc.w4 * offset_bottom_data[pc.pos4];

@masahi
Copy link

masahi commented Apr 16, 2021

Yes I remember this was a bug in ORT roi_align with max mode, where summation (for averaging) for bilinear interpolation is incorrrectly replaced with max. Maximization should be done on interpolated values, interpolation itself is always sum (averaging).

@faxu faxu removed the type:support label Aug 18, 2021
@CBlackBird
Copy link

Yes I remember this was a bug in ORT roi_align with max mode, where summation (for averaging) for bilinear interpolation is incorrrectly replaced with max. Maximization should be done on interpolated values, interpolation itself is always sum (averaging).

i found same issue, does onnxruntime will fix it on future?

@fdwr
Copy link
Contributor

fdwr commented May 10, 2022

@hariharans29 I'm unsure who the "owner" of CPU RoiAlign is, but I'll try to push my old PR again from above. Last time some tests failed because they were based on the bad expected results using the old numbers, and I don't know how they were generated in the first place. So I'm unsure what to do there, besides disabling those bad tests 🤔, but I'll sync with master to see what new/old failures surface...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions welcome lower priority issues for the core ORT teams core runtime issues related to core runtime
Projects
None yet
Development

No branches or pull requests

8 participants