Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 054bb61

Browse files
KSGulinbfineranspacemanidol
authored
Yolov5 docs update (#684)
* Initial: yolov5 docs update for v6.1 * Update: move sparseml install outside requirements.txt * Update: reference legacy hyperparam files * Fix: nit * Fix: remove redundant sparseml install * point setup to release branch Co-authored-by: Benjamin Fineran <bfineran@users.noreply.github.com> Co-authored-by: spacemanidol <dcampos3@illinois.edu>
1 parent 3f34db4 commit 054bb61

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed
File renamed without changes.

integrations/ultralytics-yolov5/models/yolov5l.yaml renamed to integrations/ultralytics-yolov5/models_v5.0/yolov5l.yaml

File renamed without changes.

integrations/ultralytics-yolov5/models/yolov5s.yaml renamed to integrations/ultralytics-yolov5/models_v5.0/yolov5s.yaml

File renamed without changes.

integrations/ultralytics-yolov5/setup_integration.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
git clone https://github.com/neuralmagic/yolov5.git
88
cd yolov5
9-
git checkout release/0.11
9+
git checkout release/0.12
1010
pip install -r requirements.txt

integrations/ultralytics-yolov5/tutorials/sparsifying_yolov5_using_recipes.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ Afterward, you will have a model that achieves roughly 0.556 mAP@0.5 or 0.654 mA
101101
102102
YOLOv5s:
103103
```bash
104-
python train.py --cfg ../models/yolov5s.yaml --weights "" --data coco.yaml --hyp data/hyp.scratch.yaml
104+
python train.py --cfg ../models_v5.0/yolov5s.yaml --weights "" --data coco.yaml --hyp data/hyps/hyp.scratch.yaml
105105
```
106106
107107
YOLOv5l:
108108
```bash
109-
python train.py --cfg ../models/yolov5l.yaml --weights "" --data coco.yaml --hyp data/hyp.scratch.yaml
109+
python train.py --cfg ../models_v5.0/yolov5l.yaml --weights "" --data coco.yaml --hyp data/hyps/hyp.scratch.yaml
110110
```
111111
2. Validate that the training commands completed successfully by checking under the newly created `runs/train/exp` path for the trained weights.
112112
The best trained weights will be found at `runs/train/exp/weights/best.pt` and will be used later for further sparsification.
@@ -150,12 +150,12 @@ The table below compares these tradeoffs and shows how to run them on the COCO d
150150
151151
| Recipe Name | Description | Train Command | COCO mAP@0.5 | Size on Disk | DeepSparse Performance** |
152152
|----------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|--------------|--------------------------|
153-
| YOLOv5s Baseline | The baseline, small YOLOv5 model used as the starting point for sparsification. | ``` python train.py --cfg ../models/yolov5s.yaml --weights "" --data coco.yaml --hyp data/hyp.scratch.yaml ``` | 0.556 | 24.8 MB | 78.2 img/sec |
154-
| [YOLOv5s Pruned](https://github.com/neuralmagic/sparseml/blob/main/integrations/ultralytics-yolov5/recipes/yolov5s.pruned.md) | Creates a highly sparse, FP32 YOLOv5s model that recovers close to the baseline model. | ``` python train.py --cfg ../models/yolov5s.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyp.scratch.yaml --recipe ../recipes/yolov5s.pruned.md ``` | 0.534 | 8.4 MB | 100.5 img/sec |
155-
| [YOLOv5s Pruned Quantized](https://github.com/neuralmagic/sparseml/blob/main/integrations/ultralytics-yolov5/recipes/yolov5s.pruned_quantized.md) | Creates a highly sparse, INT8 YOLOv5s model that recovers reasonably close to the baseline model. | ``` python train.py --cfg ../models/yolov5s.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyp.scratch.yaml --recipe ../recipes/yolov5s.pruned_quantized.md ``` | 0.525 | 3.3 MB | 198.2 img/sec |
156-
| YOLOv5l Baseline | The baseline, large YOLOv5 model used as the starting point for sparsification. | ``` python train.py --cfg ../models/yolov5l.yaml --weights "" --data coco.yaml --hyp data/hyp.scratch.yaml ``` | 0.654 | 154 MB | 22.7 img/sec |
157-
| [YOLOv5l Pruned](https://github.com/neuralmagic/sparseml/blob/main/integrations/ultralytics-yolov5/recipes/yolov5l.pruned.md) | Creates a highly sparse, FP32 YOLOv5l model that recovers close to the baseline model. | ``` python train.py --cfg ../models/yolov5l.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyp.scratch.yaml --recipe ../recipes/yolov5l.pruned.md ``` | 0.643 | 32.8 MB | 40.1 img/sec |
158-
| [YOLOv5l Pruned Quantized](https://github.com/neuralmagic/sparseml/blob/main/integrations/ultralytics-yolov5/recipes/yolov5l.pruned_quantized.md) | Creates a highly sparse, INT8 YOLOv5l model that recovers reasonably close to the baseline model. | ``` python train.py --cfg ../models/yolov5l.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyp.scratch.yaml --recipe ../recipes/yolov5l.pruned_quantized.md ``` | 0.623 | 12.7 MB | 98.6 img/sec |
153+
| YOLOv5s Baseline | The baseline, small YOLOv5 model used as the starting point for sparsification. | ``` python train.py --cfg ../models_v5.0/yolov5s.yaml --weights "" --data coco.yaml --hyp data/hyps/hyp.scratch.yaml ``` | 0.556 | 24.8 MB | 78.2 img/sec |
154+
| [YOLOv5s Pruned](https://github.com/neuralmagic/sparseml/blob/main/integrations/ultralytics-yolov5/recipes/yolov5s.pruned.md) | Creates a highly sparse, FP32 YOLOv5s model that recovers close to the baseline model. | ``` python train.py --cfg ../models_v5.0/yolov5s.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyps/hyp.scratch.yaml --recipe ../recipes/yolov5s.pruned.md ``` | 0.534 | 8.4 MB | 100.5 img/sec |
155+
| [YOLOv5s Pruned Quantized](https://github.com/neuralmagic/sparseml/blob/main/integrations/ultralytics-yolov5/recipes/yolov5s.pruned_quantized.md) | Creates a highly sparse, INT8 YOLOv5s model that recovers reasonably close to the baseline model. | ``` python train.py --cfg ../models_v5.0/yolov5s.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyps/hyp.scratch.yaml --recipe ../recipes/yolov5s.pruned_quantized.md ``` | 0.525 | 3.3 MB | 198.2 img/sec |
156+
| YOLOv5l Baseline | The baseline, large YOLOv5 model used as the starting point for sparsification. | ``` python train.py --cfg ../models_v5.0/yolov5l.yaml --weights "" --data coco.yaml --hyp data/hyps/hyp.scratch.yaml ``` | 0.654 | 154 MB | 22.7 img/sec |
157+
| [YOLOv5l Pruned](https://github.com/neuralmagic/sparseml/blob/main/integrations/ultralytics-yolov5/recipes/yolov5l.pruned.md) | Creates a highly sparse, FP32 YOLOv5l model that recovers close to the baseline model. | ``` python train.py --cfg ../models_v5.0/yolov5l.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyps/hyp.scratch.yaml --recipe ../recipes/yolov5l.pruned.md ``` | 0.643 | 32.8 MB | 40.1 img/sec |
158+
| [YOLOv5l Pruned Quantized](https://github.com/neuralmagic/sparseml/blob/main/integrations/ultralytics-yolov5/recipes/yolov5l.pruned_quantized.md) | Creates a highly sparse, INT8 YOLOv5l model that recovers reasonably close to the baseline model. | ``` python train.py --cfg ../models_v5.0/yolov5l.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyps/hyp.scratch.yaml --recipe ../recipes/yolov5l.pruned_quantized.md ``` | 0.623 | 12.7 MB | 98.6 img/sec |
159159
160160
** DeepSparse Performance measured on an AWS C5 instance with 24 cores, batch size 64, and 640x640 input with version 1.6 of the DeepSparse Engine.
161161
@@ -175,7 +175,7 @@ The table below compares these tradeoffs and shows how to run them on the COCO d
175175
3. To begin applying one of the recipes, use the `--recipe` argument within the Ultralytics [train script](https://github.com/neuralmagic/yolov5/blob/master/train.py).
176176
The recipe argument is combined with our previous training command and COCO pre-trained weights to run the recipes over the model. For example, a command for YOLOv5s would look like this:
177177
```bash
178-
python train.py --cfg ../models/yolov5s.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyp.scratch.yaml --recipe PATH_TO_SPARSIFICATION_RECIPE
178+
python train.py --cfg ../models_v5.0/yolov5s.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyps/hyp.scratch.yaml --recipe PATH_TO_SPARSIFICATION_RECIPE
179179
```
180180
After applying a recipe, you are ready to export for inference.
181181
@@ -218,12 +218,12 @@ The `best.pt` file contains a checkpoint of the best weights measured on the val
218218
These weights can be loaded into the `train.py` and `test.py` scripts now.
219219
However, other formats are generally more friendly for other inference deployment platforms, such as [ONNX](https://onnx.ai/).
220220
221-
The [`export.py` script](https://github.com/neuralmagic/yolov5/blob/master/models/export.py) handles the logic behind loading the checkpoint and converting it into the more common inference formats, as described here.
221+
The [`export.py` script](https://github.com/neuralmagic/yolov5/blob/master/export.py) handles the logic behind loading the checkpoint and converting it into the more common inference formats, as described here.
222222
223223
1. Enter the following command to load the PyTorch graph, convert to ONNX, and correct any misformatted pieces of the graph for the pruned and quantized models.
224224
225225
```bash
226-
python models/export.py --weights PATH_TO_SPARSIFIED_WEIGHTS --dynamic
226+
python export.py --weights PATH_TO_SPARSIFIED_WEIGHTS --dynamic
227227
```
228228
229229
The result is a new file added next to the sparsified checkpoint with a `.onnx` extension:

integrations/ultralytics-yolov5/tutorials/yolov5_sparse_transfer_learning.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,27 @@ The recipes are specific to the sparsification type, so the training command wil
119119

120120
- YOLOv5s Pruned transfer learning:
121121
```bash
122-
python train.py --data voc.yaml --cfg ../models/yolov5s.yaml --weights zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned-aggressive_96?recipe_type=transfer --hyp data/hyp.finetune.yaml --recipe ../recipes/yolov5.transfer_learn_pruned.md
122+
python train.py --data VOC.yaml --cfg ../models_v5.0/yolov5s.yaml --weights zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned-aggressive_96?recipe_type=transfer --hyp data/hyps/hyp.finetune.yaml --recipe ../recipes/yolov5.transfer_learn_pruned.md
123123
```
124124
- YOLOv5s Pruned-Quantized transfer learning:
125125
```bash
126-
python train.py --data voc.yaml --cfg ../models/yolov5s.yaml --weights zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned_quant-aggressive_94?recipe_type=transfer --hyp data/hyp.finetune.yaml --recipe ../recipes/yolov5.transfer_learn_pruned_quantized.md
126+
python train.py --data VOC.yaml --cfg ../models_v5.0/yolov5s.yaml --weights zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned_quant-aggressive_94?recipe_type=transfer --hyp data/hyps/hyp.finetune.yaml --recipe ../recipes/yolov5.transfer_learn_pruned_quantized.md
127127
```
128128
- YOLOv5s Baseline transfer learning:
129129
```bash
130-
python train.py --data voc.yaml --cfg ../models/yolov5s.yaml --weights zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none --hyp data/hyp.finetune.yaml --epochs 50
130+
python train.py --data VOC.yaml --cfg ../models_v5.0/yolov5s.yaml --weights zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none --hyp data/hyps/hyp.finetune.yaml --epochs 50
131131
```
132132
- YOLOv5l Pruned transfer learning:
133133
```bash
134-
python train.py --data voc.yaml --cfg ../models/yolov5l.yaml --weights zoo:cv/detection/yolov5-l/pytorch/ultralytics/coco/pruned-aggressive_98?recipe_type=transfer --hyp data/hyp.finetune.yaml --recipe ../recipes/yolov5.transfer_learn_pruned.md
134+
python train.py --data VOC.yaml --cfg ../models_v5.0/yolov5l.yaml --weights zoo:cv/detection/yolov5-l/pytorch/ultralytics/coco/pruned-aggressive_98?recipe_type=transfer --hyp data/hyps/hyp.finetune.yaml --recipe ../recipes/yolov5.transfer_learn_pruned.md
135135
```
136136
- YOLOv5l Pruned-Quantized transfer learning:
137137
```bash
138-
python train.py --data voc.yaml --cfg ../models/yolov5l.yaml --weights zoo:cv/detection/yolov5-l/pytorch/ultralytics/coco/pruned_quant-aggressive_95?recipe_type=transfer --hyp data/hyp.finetune.yaml --recipe ../recipes/yolov5.transfer_learn_pruned_quantized.md
138+
python train.py --data VOC.yaml --cfg ../models_v5.0/yolov5l.yaml --weights zoo:cv/detection/yolov5-l/pytorch/ultralytics/coco/pruned_quant-aggressive_95?recipe_type=transfer --hyp data/hyps/hyp.finetune.yaml --recipe ../recipes/yolov5.transfer_learn_pruned_quantized.md
139139
```
140140
- YOLOv5l Baseline transfer learning:
141141
```bash
142-
python train.py --data voc.yaml --cfg ../models/yolov5l.yaml --weights zoo:cv/detection/yolov5-l/pytorch/ultralytics/coco/base-none --hyp data/hyp.finetune.yaml --epochs 50
142+
python train.py --data VOC.yaml --cfg ../models_v5.0/yolov5l.yaml --weights zoo:cv/detection/yolov5-l/pytorch/ultralytics/coco/base-none --hyp data/hyps/hyp.finetune.yaml --epochs 50
143143
```
144144

145145
**_Notes About Transfer Learning_**
@@ -200,11 +200,11 @@ The `best.pt` file, located in the previous step, contains a checkpoint of the b
200200
These weights can be loaded into the `train.py` and `test.py` scripts now.
201201
However, other formats are generally more friendly for other inference deployment platforms, such as [ONNX](https://onnx.ai/).
202202
203-
The [export.py script](https://github.com/neuralmagic/yolov5/blob/master/models/export.py) handles the logic behind loading the checkpoint and converting it into the more common inference formats, as described here.
203+
The [export.py script](https://github.com/neuralmagic/yolov5/blob/master/export.py) handles the logic behind loading the checkpoint and converting it into the more common inference formats, as described here.
204204
205205
1. Enter the following command to load the PyTorch graph, convert to ONNX, and correct any misformatted pieces of the graph for the pruned and quantized models.
206206
```bash
207-
python models/export.py --weights PATH_TO_SPARSIFIED_WEIGHTS --dynamic
207+
python export.py --weights PATH_TO_SPARSIFIED_WEIGHTS --dynamic
208208
```
209209
The result is a new file added next to the sparsified checkpoint with a `.onnx` extension:
210210
```

0 commit comments

Comments
 (0)