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 YOLOv5 Detect Layer compatibility #345

Merged
merged 5 commits into from
Mar 8, 2022
Merged

Fix YOLOv5 Detect Layer compatibility #345

merged 5 commits into from
Mar 8, 2022

Conversation

zhiqwang
Copy link
Owner

@zhiqwang zhiqwang commented Mar 8, 2022

Let's use YOLOv5's layout to load the trained checkpoints. Currently this tool load_yolov5_model() is mainly used to load the checkpoints trained by yolov5 with support for versions v3.1, v4.0 (v5.0) and v6.0 (v6.1). In addition it is available for inference with AutoShape attached for versions v6.0 (v6.1).

from torch import Tensor
from yolort.v5 import AutoShape, attempt_download, load_yolov5_model

img_path = "test/assets/zidane.jpg"

model_url = "https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5s.pt"
checkpoint_path = attempt_download(model_url, hash_prefix="8b3b748c")

model = load_yolov5_model(checkpoint_path)
# Attach AutoShape
model = AutoShape(model)

results = model(img_path)

assert isinstance(results.pred, list)
assert len(results.pred) == 1
assert isinstance(results.pred[0], Tensor)
assert results.pred[0].shape == (4, 6)

@zhiqwang zhiqwang added the bug / fix Something isn't working label Mar 8, 2022
@codecov
Copy link

codecov bot commented Mar 8, 2022

Codecov Report

Merging #345 (875eefa) into main (719f76f) will increase coverage by 0.37%.
The diff coverage is 53.84%.

❗ Current head 875eefa differs from pull request most recent head d0ebe9e. Consider uploading reports for the commit d0ebe9e to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #345      +/-   ##
==========================================
+ Coverage   95.53%   95.90%   +0.37%     
==========================================
  Files          11       11              
  Lines         783      781       -2     
==========================================
+ Hits          748      749       +1     
+ Misses         35       32       -3     
Flag Coverage Δ
unittests 95.90% <53.84%> (+0.37%) ⬆️

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

Impacted Files Coverage Δ
test/test_utils.py 80.37% <0.00%> (+2.19%) ⬆️
test/test_v5.py 100.00% <100.00%> (ø)

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 719f76f...d0ebe9e. Read the comment docs.

@zhiqwang zhiqwang merged commit 79cb37d into main Mar 8, 2022
@zhiqwang zhiqwang deleted the fix-custom-P6 branch March 8, 2022 14:02
zhiqwang added a commit that referenced this pull request Mar 8, 2022
* Adopt the new Detect Layer compatibility

* Set fuse False as default

* Cleanup test

* Fix docstring and unittest

* Fix docstrings
zhiqwang added a commit that referenced this pull request Mar 8, 2022
* Adopt the new Detect Layer compatibility

* Set fuse False as default

* Cleanup test

* Fix docstring and unittest

* Fix docstrings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant