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

Fix the consistency of pre-processing with yolov5 #293

Merged
merged 49 commits into from
Feb 4, 2022

Conversation

triple-Mu
Copy link
Contributor

@triple-Mu triple-Mu commented Jan 26, 2022

Aligning the YOLOTransform with the letterbox in yolov5.

Fortunately, the interpolation operator of PyTorch is aligned with that of OpenCV for the float type, however, PyTorch's interpolate does not currently support integers type: pytorch/pytorch#5580 , a little loss of precision will occur here.

https://github.com/zhiqwang/yolov5-rt-stack/blob/cd1a6ec7cda09de0dc92962a37ecb4f723a8dfeb/test/test_models_transform.py#L31-L53

Close #274 .

@codecov
Copy link

codecov bot commented Jan 26, 2022

Codecov Report

Merging #293 (3394321) into main (c6131f4) will increase coverage by 0.91%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #293      +/-   ##
==========================================
+ Coverage   94.01%   94.92%   +0.91%     
==========================================
  Files          11       11              
  Lines         718      729      +11     
==========================================
+ Hits          675      692      +17     
+ Misses         43       37       -6     
Flag Coverage Δ
unittests 94.92% <100.00%> (+0.91%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
test/test_engine.py 100.00% <100.00%> (ø)
test/test_models.py 95.86% <100.00%> (ø)
test/test_models_transform.py 100.00% <100.00%> (ø)
test/test_onnx.py 94.11% <100.00%> (+8.40%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6131f4...3394321. Read the comment docs.

@CLAassistant
Copy link

CLAassistant commented Jan 27, 2022

CLA assistant check
All committers have signed the CLA.

@zhiqwang zhiqwang force-pushed the main branch 2 times, most recently from 147afb2 to c557fec Compare January 27, 2022 17:30
@zhiqwang zhiqwang changed the title Add letterbox function Fix the consistency of pre-processing with yolov5 Jan 28, 2022
@zhiqwang zhiqwang added the bug / fix Something isn't working label Jan 28, 2022
@zhiqwang zhiqwang force-pushed the main branch 3 times, most recently from fe436f1 to 79a6e61 Compare January 29, 2022 05:18
@zhiqwang zhiqwang added the bc-breaking Backwards Incompatible Changes label Jan 29, 2022
aug2 = out2[0].astype(np.float32) # uint8 to float32
aug2 = np.transpose(aug2 / 255.0, [2, 0, 1])
assert aug1.shape == aug2.shape
np.testing.assert_allclose(aug1, aug2, rtol=1e-4, atol=1e-2)
Copy link
Owner

@zhiqwang zhiqwang Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyTorch's interpolate operator now only aligns with OpenCV for the float type, and the letterbox implemented by yolov5 operates on uint8, so the precision we set here is relatively low.

Check pytorch/pytorch#5580 (comment) for more details.

@zhiqwang zhiqwang merged commit cd1a6ec into zhiqwang:main Feb 4, 2022
@zhiqwang zhiqwang added the API Library use interface label Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Library use interface bc-breaking Backwards Incompatible Changes bug / fix Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the pre-processing consistent with yolov5
3 participants