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

Add comparison docs for yolov5 & yolort #300

Merged
merged 7 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
html_favicon = "_static/favicon.svg"
html_logo = "_static/yolort_logo.png"
html_logo = "_static/yolort_logo_icon.png"

mathjax_path = "mathjax/tex-chtml.js"

Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ And we support loading the trained weights from YOLOv5:
:caption: Tutorials

notebooks/inference-pytorch-export-libtorch
notebooks/comparison-between-yolort-vs-yolov5
notebooks/how-to-align-with-ultralytics-yolov5
notebooks/anchor-label-assignment-visualization
notebooks/model-graph-visualization
Expand Down
586 changes: 586 additions & 0 deletions notebooks/comparison-between-yolort-vs-yolov5.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_read_image_to_tensor():


def test_get_image_from_url():
url = "https://raw.githubusercontent.com/zhiqwang/yolov5-rt-stack/master/test/assets/zidane.jpg"
url = "https://huggingface.co/spaces/zhiqwang/assets/resolve/main/zidane.jpg"
img = get_image_from_url(url)
assert isinstance(img, np.ndarray)
assert tuple(img.shape) == (720, 1280, 3)
Expand Down
12 changes: 7 additions & 5 deletions yolort/models/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ def _resize_image_and_masks(
class YOLOTransform(nn.Module):
"""
Performs input / target transformation before feeding the data to a YOLO model. It plays
the same role of `LetterBox`, and YOLOv5 adopt (0, 1, RGB) as the default mean, std and
channel mode. We do not normalize below, the inputs need to be scaled down to float [0-1]
from int[0-255] and transpose the image channel to RGB before being fed to this transformation.
the same role of `LetterBox` in YOLOv5. YOLOv5 use (0, 1, RGB) as the default mean, std and
color channel mode. We do not normalize below, the inputs need to be scaled down to float
in [0-1] from uint8 in [0-255] and transpose the color channel to RGB before being fed to
this transformation. We use the `torch.nn.functional.interpolate` and `torch.nn.functional.pad`
ops to implement the `LetterBox` to make it jit traceable and scriptable.

The transformations it perform are:
- input / target resizing to get a rectangle within shape `(height, width)` that
can be divided by `size_divisible`
- resizing input / target that maintains the aspect ratio within shape `(height, width)`
- letterboxing padding the input / target that can be divided by `size_divisible`

It returns a `NestedTensor` for the inputs, and a List[Dict[Tensor]] for the targets.

Expand Down
3 changes: 1 addition & 2 deletions yolort/models/yolo_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

class YOLOv5(LightningModule):
"""
Wrapping the pre-processing into YOLO models, we use the `torch.nn.functional.interpolate`
and `torch.nn.functional.pad` ops to implement the letterbox to make it scriptable.
Wrapping the pre-processing (`LetterBox`) into the YOLO models.

Args:
lr (float): The initial learning rate
Expand Down