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

first about DataLoader and Trainer #504

Closed
Closed
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
4 changes: 2 additions & 2 deletions deployment/tensorrt-yolov6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
1. 下载 yolort 源码:

```sh
git clone https://github.com/zhiqwang/yolort.git
cd yolort/deployment/tensorrt-yolov6
git clone https://github.com/zhiqwang/yolov5-rt-stack.git
cd yolov5-rt-stack/deployment/tensorrt-yolov6
```

1. 导出 ONNX 的时候请务必包含 EfficientNMS 算子, 稍后我们会加入一个更清晰的流程. ~从 YOLOv6 官方地址下载 ONNX 模型,如 [yolov6n.onnx](https://github.com/meituan/YOLOv6/releases/download/0.1.0/yolov6n.onnx)~.
Expand Down
2 changes: 1 addition & 1 deletion deployment/tensorrt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The TensorRT inference example of `yolort`.

## Usage

Here we will mainly discuss how to use the C++ interface, we recommend that you check out our [tutorial](https://zhiqwang.com/yolort/notebooks/onnx-graphsurgeon-inference-tensorrt.html) first.
Here we will mainly discuss how to use the C++ interface, we recommend that you check out our [tutorial](https://zhiqwang.com/yolov5-rt-stack/notebooks/onnx-graphsurgeon-inference-tensorrt.html) first.

1. Export your custom model to TensorRT format

Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def setup(app):

nbsphinx_epilog = """
View this document as a notebook:
https://github.com/zhiqwang/yolort/blob/main/{{ env.doc2path(env.docname, base=None) }}
https://github.com/zhiqwang/yolov5-rt-stack/blob/main/{{ env.doc2path(env.docname, base=None) }}

----
"""
Expand All @@ -106,12 +106,12 @@ def setup(app):
# "google_analytics_account": "UA-XXXXX",
# Specify a base_url used to generate sitemap.xml. If not
# specified, then no sitemap will be built.
"base_url": "https://zhiqwang.com/yolort",
"base_url": "https://zhiqwang.com/yolov5-rt-stack",
# Set the color and the accent color
"color_primary": "blue",
"color_accent": "light-blue",
# Set the repo location to get a badge with stats
"repo_url": "https://github.com/zhiqwang/yolort/",
"repo_url": "https://github.com/zhiqwang/yolov5-rt-stack/",
"repo_name": "yolort",
# Visible levels of the global TOC; -1 means unlimited
"globaltoc_depth": 3,
Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ Read a source of image(s) and detect its objects:
And we support loading the trained weights from YOLOv5. Please see our documents on what
we `share`_ and how we `differ`_ from yolov5 for more details.

.. _share: https://zhiqwang.com/yolort/notebooks/how-to-align-with-ultralytics-yolov5.html
.. _differ: https://zhiqwang.com/yolort/notebooks/comparison-between-yolort-vs-yolov5.html
.. _share: https://zhiqwang.com/yolov5-rt-stack/notebooks/how-to-align-with-ultralytics-yolov5.html
.. _differ: https://zhiqwang.com/yolov5-rt-stack/notebooks/comparison-between-yolort-vs-yolov5.html

.. code:: python

Expand Down
4 changes: 2 additions & 2 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ install PyTorch 1.8.0+ and torchvision 0.9.0+.

To install yolort, you may either use the repository

https://github.com/zhiqwang/yolort/
https://github.com/zhiqwang/yolov5-rt-stack/

and ``setup.py`` from there or use

Expand All @@ -22,7 +22,7 @@ to get the latest release and

::

pip install 'git+https://github.com/zhiqwang/yolort.git'
pip install 'git+https://github.com/zhiqwang/yolov5-rt-stack.git'

to install the development version.

Expand Down
Empty file added exps/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions exps/default/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.
35 changes: 35 additions & 0 deletions exps/default/yolov3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.

import os

import torch.nn as nn

from yolort.exp import Exp as MyExp


class Exp(MyExp):
def __init__(self):
super(Exp, self).__init__()
self.depth = 1.0
self.width = 1.0
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]

def get_model(self, sublinear=False):
def init_yolo(M):
for m in M.modules():
if isinstance(m, nn.BatchNorm2d):
m.eps = 1e-3
m.momentum = 0.03

if "model" not in self.__dict__:
from yolort.models import YOLOFPN, YOLOX, YOLOXHead

backbone = YOLOFPN()
head = YOLOXHead(self.num_classes, self.width, in_channels=[128, 256, 512], act="lrelu")
self.model = YOLOX(backbone, head)
self.model.apply(init_yolo)
self.model.head.initialize_biases(1e-2)

return self.model
15 changes: 15 additions & 0 deletions exps/default/yolox_l.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.

import os

from yolort.exp import Exp as MyExp


class Exp(MyExp):
def __init__(self):
super(Exp, self).__init__()
self.depth = 1.0
self.width = 1.0
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
15 changes: 15 additions & 0 deletions exps/default/yolox_m.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.

import os

from yolort.exp import Exp as MyExp


class Exp(MyExp):
def __init__(self):
super(Exp, self).__init__()
self.depth = 0.67
self.width = 0.75
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
51 changes: 51 additions & 0 deletions exps/default/yolox_nano.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.

import os

import torch.nn as nn

from yolort.exp import Exp as MyExp


class Exp(MyExp):
def __init__(self):
super(Exp, self).__init__()
self.depth = 0.33
self.width = 0.25
self.input_size = (416, 416)
self.random_size = (10, 20)
self.mosaic_scale = (0.5, 1.5)
self.test_size = (416, 416)
self.mosaic_prob = 0.5
self.enable_mixup = False
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]

def get_model(self, sublinear=False):
def init_yolo(M):
for m in M.modules():
if isinstance(m, nn.BatchNorm2d):
m.eps = 1e-3
m.momentum = 0.03

if "model" not in self.__dict__:
from yolort.models import YOLOPAFPN, YOLOX, YOLOXHead

in_channels = [256, 512, 1024]
# NANO model use depthwise = True, which is main difference.
backbone = YOLOPAFPN(
self.depth,
self.width,
in_channels=in_channels,
act=self.act,
depthwise=True,
)
head = YOLOXHead(
self.num_classes, self.width, in_channels=in_channels, act=self.act, depthwise=True
)
self.model = YOLOX(backbone, head)

self.model.apply(init_yolo)
self.model.head.initialize_biases(1e-2)
return self.model
15 changes: 15 additions & 0 deletions exps/default/yolox_s.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.

import os

from yolort.exp import Exp as MyExp


class Exp(MyExp):
def __init__(self):
super(Exp, self).__init__()
self.depth = 0.33
self.width = 0.50
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
20 changes: 20 additions & 0 deletions exps/default/yolox_tiny.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.

import os

from yolort.exp import Exp as MyExp


class Exp(MyExp):
def __init__(self):
super(Exp, self).__init__()
self.depth = 0.33
self.width = 0.375
self.input_size = (416, 416)
self.mosaic_scale = (0.5, 1.5)
self.random_size = (10, 20)
self.test_size = (416, 416)
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
self.enable_mixup = False
15 changes: 15 additions & 0 deletions exps/default/yolox_x.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.

import os

from yolort.exp import Exp as MyExp


class Exp(MyExp):
def __init__(self):
super(Exp, self).__init__()
self.depth = 1.33
self.width = 1.25
self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
2 changes: 1 addition & 1 deletion notebooks/comparison-between-yolort-vs-yolov5.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"\n",
"For pre-processing, YOLOv5 uses the [letterboxing (padding)](https://en.wikipedia.org/wiki/Letterboxing_(filming)) resizing that maintains the aspect ratio. The error arises from the `interpolate` operator used in resizing. YOLOv5 uses the [cv2.resize](https://docs.opencv.org/4.x/da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d) operator on the input `uint8 [0-255]` images, the operators in OpenCV are not traceable or scriptable, so we use [torch.nn.functional.interpolate](https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html#torch-nn-functional-interpolate) in yolort. Fortunately, the `interpolation` operator of PyTorch is [aligned](https://github.com/pytorch/vision/issues/2950#issuecomment-723038041) with that of OpenCV, however PyTorch's `interpolate` [only supports](https://github.com/pytorch/pytorch/issues/5580) the float data type now, we can only operate with images cast to float types, and therefore there will introduce some errors.\n",
"\n",
"YOLOv5 provides a very powerful function to do the post-processing, of which we implement only a non-agnostic version, but the accuracy here should be able to be consistent with the original version. See our [doc](https://zhiqwang.com/yolort/notebooks/how-to-align-with-ultralytics-yolov5.html) for more details.\n",
"YOLOv5 provides a very powerful function to do the post-processing, of which we implement only a non-agnostic version, but the accuracy here should be able to be consistent with the original version. See our [doc](https://zhiqwang.com/yolov5-rt-stack/notebooks/how-to-align-with-ultralytics-yolov5.html) for more details.\n",
"\n",
"## Prepare environment, image and model weights to test"
]
Expand Down
10 changes: 5 additions & 5 deletions notebooks/export-onnx-inference-onnxruntime.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@
"text": [
"/opt/conda/lib/python3.8/site-packages/torch/nn/functional.py:3701: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).\n",
" (torch.floor((input.size(i + 2).float() * torch.tensor(scale_factors[i], dtype=torch.float32)).float()))\n",
"/coding/yolort/yolort/models/transform.py:282: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n",
"/coding/yolov5-rt-stack/yolort/models/transform.py:282: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n",
" img_h, img_w = _get_shape_onnx(img)\n",
"/coding/yolort/yolort/models/anchor_utils.py:45: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.\n",
"/coding/yolov5-rt-stack/yolort/models/anchor_utils.py:45: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.\n",
" anchors = torch.as_tensor(self.anchor_grids, dtype=torch.float32, device=device).to(dtype=dtype)\n",
"/coding/yolort/yolort/models/anchor_utils.py:46: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.\n",
"/coding/yolov5-rt-stack/yolort/models/anchor_utils.py:46: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.\n",
" strides = torch.as_tensor(self.strides, dtype=torch.float32, device=device).to(dtype=dtype)\n",
"/coding/yolort/yolort/models/box_head.py:402: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.\n",
"/coding/yolov5-rt-stack/yolort/models/box_head.py:402: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.\n",
" strides = torch.as_tensor(self.strides, dtype=torch.float32, device=device).to(dtype=dtype)\n",
"/coding/yolort/yolort/models/box_head.py:333: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n",
"/coding/yolov5-rt-stack/yolort/models/box_head.py:333: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n",
" for head_output, grid, shift, stride in zip(head_outputs, grids, shifts, strides):\n",
"/opt/conda/lib/python3.8/site-packages/torch/onnx/symbolic_opset9.py:2815: UserWarning: Exporting aten::index operator of advanced indexing in opset 11 is achieved by combination of multiple ONNX operators, including Reshape, Transpose, Concat, and Gather. If indices include negative values, the exported graph will produce incorrect results.\n",
" warnings.warn(\"Exporting aten::index operator of advanced indexing in opset \" +\n"
Expand Down
Loading
Loading