From 7e3857843c1dc28de07dadf27cc0feebd770fbaa Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 6 Apr 2022 15:54:42 -0400 Subject: [PATCH 1/6] Initial: yolov5 docs update for v6.1 --- .../{models => models_v5.0}/.gitkeep | 0 .../{models => models_v5.0}/yolov5l.yaml | 0 .../{models => models_v5.0}/yolov5s.yaml | 0 .../ultralytics-yolov5/setup_integration.sh | 2 +- .../sparsifying_yolov5_using_recipes.md | 22 +++++++++---------- .../yolov5_sparse_transfer_learning.md | 16 +++++++------- 6 files changed, 20 insertions(+), 20 deletions(-) rename integrations/ultralytics-yolov5/{models => models_v5.0}/.gitkeep (100%) rename integrations/ultralytics-yolov5/{models => models_v5.0}/yolov5l.yaml (100%) rename integrations/ultralytics-yolov5/{models => models_v5.0}/yolov5s.yaml (100%) mode change 100644 => 100755 integrations/ultralytics-yolov5/setup_integration.sh diff --git a/integrations/ultralytics-yolov5/models/.gitkeep b/integrations/ultralytics-yolov5/models_v5.0/.gitkeep similarity index 100% rename from integrations/ultralytics-yolov5/models/.gitkeep rename to integrations/ultralytics-yolov5/models_v5.0/.gitkeep diff --git a/integrations/ultralytics-yolov5/models/yolov5l.yaml b/integrations/ultralytics-yolov5/models_v5.0/yolov5l.yaml similarity index 100% rename from integrations/ultralytics-yolov5/models/yolov5l.yaml rename to integrations/ultralytics-yolov5/models_v5.0/yolov5l.yaml diff --git a/integrations/ultralytics-yolov5/models/yolov5s.yaml b/integrations/ultralytics-yolov5/models_v5.0/yolov5s.yaml similarity index 100% rename from integrations/ultralytics-yolov5/models/yolov5s.yaml rename to integrations/ultralytics-yolov5/models_v5.0/yolov5s.yaml diff --git a/integrations/ultralytics-yolov5/setup_integration.sh b/integrations/ultralytics-yolov5/setup_integration.sh old mode 100644 new mode 100755 index 09647ba625a..22de931ea7a --- a/integrations/ultralytics-yolov5/setup_integration.sh +++ b/integrations/ultralytics-yolov5/setup_integration.sh @@ -6,5 +6,5 @@ git clone https://github.com/neuralmagic/yolov5.git cd yolov5 -git checkout release/0.11 +git checkout release/0.12 pip install -r requirements.txt diff --git a/integrations/ultralytics-yolov5/tutorials/sparsifying_yolov5_using_recipes.md b/integrations/ultralytics-yolov5/tutorials/sparsifying_yolov5_using_recipes.md index 73e94fa4e93..8827e4dce70 100644 --- a/integrations/ultralytics-yolov5/tutorials/sparsifying_yolov5_using_recipes.md +++ b/integrations/ultralytics-yolov5/tutorials/sparsifying_yolov5_using_recipes.md @@ -101,12 +101,12 @@ Afterward, you will have a model that achieves roughly 0.556 mAP@0.5 or 0.654 mA YOLOv5s: ```bash - python train.py --cfg ../models/yolov5s.yaml --weights "" --data coco.yaml --hyp data/hyp.scratch.yaml + python train.py --cfg ../models_v5.0/yolov5s.yaml --weights "" --data coco.yaml --hyp data/hyps/hyp.scratch-low.yaml ``` YOLOv5l: ```bash - python train.py --cfg ../models/yolov5l.yaml --weights "" --data coco.yaml --hyp data/hyp.scratch.yaml + python train.py --cfg ../models_v5.0/yolov5l.yaml --weights "" --data coco.yaml --hyp data/hyps/hyp.scratch-low.yaml ``` 2. Validate that the training commands completed successfully by checking under the newly created `runs/train/exp` path for the trained weights. 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 | Recipe Name | Description | Train Command | COCO mAP@0.5 | Size on Disk | DeepSparse Performance** | |----------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|--------------|--------------------------| - | 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 | - | [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 | - | [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 | - | 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 | - | [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 | - | [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 | + | 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-low.yaml ``` | 0.556 | 24.8 MB | 78.2 img/sec | + | [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-low.yaml --recipe ../recipes/yolov5s.pruned.md ``` | 0.534 | 8.4 MB | 100.5 img/sec | + | [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-low.yaml --recipe ../recipes/yolov5s.pruned_quantized.md ``` | 0.525 | 3.3 MB | 198.2 img/sec | + | 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-low.yaml ``` | 0.654 | 154 MB | 22.7 img/sec | + | [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-low.yaml --recipe ../recipes/yolov5l.pruned.md ``` | 0.643 | 32.8 MB | 40.1 img/sec | + | [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-low.yaml --recipe ../recipes/yolov5l.pruned_quantized.md ``` | 0.623 | 12.7 MB | 98.6 img/sec | ** 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. @@ -175,7 +175,7 @@ The table below compares these tradeoffs and shows how to run them on the COCO d 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). 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: ```bash - 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 + python train.py --cfg ../models_v5.0/yolov5s.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyps/hyp.scratch-low.yaml --recipe PATH_TO_SPARSIFICATION_RECIPE ``` After applying a recipe, you are ready to export for inference. @@ -218,12 +218,12 @@ The `best.pt` file contains a checkpoint of the best weights measured on the val These weights can be loaded into the `train.py` and `test.py` scripts now. However, other formats are generally more friendly for other inference deployment platforms, such as [ONNX](https://onnx.ai/). -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. +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. 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. ```bash - python models/export.py --weights PATH_TO_SPARSIFIED_WEIGHTS --dynamic + python export.py --weights PATH_TO_SPARSIFIED_WEIGHTS --dynamic ``` The result is a new file added next to the sparsified checkpoint with a `.onnx` extension: diff --git a/integrations/ultralytics-yolov5/tutorials/yolov5_sparse_transfer_learning.md b/integrations/ultralytics-yolov5/tutorials/yolov5_sparse_transfer_learning.md index de21786a3ba..e830245d29f 100644 --- a/integrations/ultralytics-yolov5/tutorials/yolov5_sparse_transfer_learning.md +++ b/integrations/ultralytics-yolov5/tutorials/yolov5_sparse_transfer_learning.md @@ -119,27 +119,27 @@ The recipes are specific to the sparsification type, so the training command wil - YOLOv5s Pruned transfer learning: ```bash - 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 + 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.VOC.yaml --recipe ../recipes/yolov5.transfer_learn_pruned.md ``` - YOLOv5s Pruned-Quantized transfer learning: ```bash - 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 + 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.VOC.yaml --recipe ../recipes/yolov5.transfer_learn_pruned_quantized.md ``` - YOLOv5s Baseline transfer learning: ```bash - 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 + 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.VOC.yaml --epochs 50 ``` - YOLOv5l Pruned transfer learning: ```bash - 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 + 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.VOC.yaml --recipe ../recipes/yolov5.transfer_learn_pruned.md ``` - YOLOv5l Pruned-Quantized transfer learning: ```bash - 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 + 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.VOC.yaml --recipe ../recipes/yolov5.transfer_learn_pruned_quantized.md ``` - YOLOv5l Baseline transfer learning: ```bash - 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 + 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.VOC.yaml --epochs 50 ``` **_Notes About Transfer Learning_** @@ -200,11 +200,11 @@ The `best.pt` file, located in the previous step, contains a checkpoint of the b These weights can be loaded into the `train.py` and `test.py` scripts now. However, other formats are generally more friendly for other inference deployment platforms, such as [ONNX](https://onnx.ai/). -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. +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. 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. ```bash - python models/export.py --weights PATH_TO_SPARSIFIED_WEIGHTS --dynamic + python export.py --weights PATH_TO_SPARSIFIED_WEIGHTS --dynamic ``` The result is a new file added next to the sparsified checkpoint with a `.onnx` extension: ``` From cef6490382cf1df0cd1a738edd4d25c652377c2f Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 6 Apr 2022 16:01:45 -0400 Subject: [PATCH 2/6] Update: move sparseml install outside requirements.txt --- integrations/ultralytics-yolov5/setup_integration.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/integrations/ultralytics-yolov5/setup_integration.sh b/integrations/ultralytics-yolov5/setup_integration.sh index 22de931ea7a..e9e08254728 100755 --- a/integrations/ultralytics-yolov5/setup_integration.sh +++ b/integrations/ultralytics-yolov5/setup_integration.sh @@ -8,3 +8,4 @@ git clone https://github.com/neuralmagic/yolov5.git cd yolov5 git checkout release/0.12 pip install -r requirements.txt +pip install sparseml[torch, torchvision] From 292421e7fba0b03ef7268b9e6f8e2404cdec2bbb Mon Sep 17 00:00:00 2001 From: Konstantin Date: Fri, 8 Apr 2022 07:22:23 -0400 Subject: [PATCH 3/6] Update: reference legacy hyperparam files --- .../sparsifying_yolov5_using_recipes.md | 18 +++++++++--------- .../yolov5_sparse_transfer_learning.md | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/integrations/ultralytics-yolov5/tutorials/sparsifying_yolov5_using_recipes.md b/integrations/ultralytics-yolov5/tutorials/sparsifying_yolov5_using_recipes.md index 8827e4dce70..53b45566039 100644 --- a/integrations/ultralytics-yolov5/tutorials/sparsifying_yolov5_using_recipes.md +++ b/integrations/ultralytics-yolov5/tutorials/sparsifying_yolov5_using_recipes.md @@ -101,12 +101,12 @@ Afterward, you will have a model that achieves roughly 0.556 mAP@0.5 or 0.654 mA YOLOv5s: ```bash - python train.py --cfg ../models_v5.0/yolov5s.yaml --weights "" --data coco.yaml --hyp data/hyps/hyp.scratch-low.yaml + python train.py --cfg ../models_v5.0/yolov5s.yaml --weights "" --data coco.yaml --hyp data/hyps/hyp.scratch.yaml ``` YOLOv5l: ```bash - python train.py --cfg ../models_v5.0/yolov5l.yaml --weights "" --data coco.yaml --hyp data/hyps/hyp.scratch-low.yaml + python train.py --cfg ../models_v5.0/yolov5l.yaml --weights "" --data coco.yaml --hyp data/hyps/hyp.scratch.yaml ``` 2. Validate that the training commands completed successfully by checking under the newly created `runs/train/exp` path for the trained weights. 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 | Recipe Name | Description | Train Command | COCO mAP@0.5 | Size on Disk | DeepSparse Performance** | |----------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|--------------|--------------------------| - | 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-low.yaml ``` | 0.556 | 24.8 MB | 78.2 img/sec | - | [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-low.yaml --recipe ../recipes/yolov5s.pruned.md ``` | 0.534 | 8.4 MB | 100.5 img/sec | - | [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-low.yaml --recipe ../recipes/yolov5s.pruned_quantized.md ``` | 0.525 | 3.3 MB | 198.2 img/sec | - | 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-low.yaml ``` | 0.654 | 154 MB | 22.7 img/sec | - | [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-low.yaml --recipe ../recipes/yolov5l.pruned.md ``` | 0.643 | 32.8 MB | 40.1 img/sec | - | [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-low.yaml --recipe ../recipes/yolov5l.pruned_quantized.md ``` | 0.623 | 12.7 MB | 98.6 img/sec | + | 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 | + | [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 | + | [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 | + | 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 | + | [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 | + | [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 | ** 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. @@ -175,7 +175,7 @@ The table below compares these tradeoffs and shows how to run them on the COCO d 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). 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: ```bash - python train.py --cfg ../models_v5.0/yolov5s.yaml --weights PATH_TO_COCO_PRETRAINED_WEIGHTS --data coco.yaml --hyp data/hyps/hyp.scratch-low.yaml --recipe PATH_TO_SPARSIFICATION_RECIPE + 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 ``` After applying a recipe, you are ready to export for inference. diff --git a/integrations/ultralytics-yolov5/tutorials/yolov5_sparse_transfer_learning.md b/integrations/ultralytics-yolov5/tutorials/yolov5_sparse_transfer_learning.md index e830245d29f..17c6d5c0051 100644 --- a/integrations/ultralytics-yolov5/tutorials/yolov5_sparse_transfer_learning.md +++ b/integrations/ultralytics-yolov5/tutorials/yolov5_sparse_transfer_learning.md @@ -119,27 +119,27 @@ The recipes are specific to the sparsification type, so the training command wil - YOLOv5s Pruned transfer learning: ```bash - 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.VOC.yaml --recipe ../recipes/yolov5.transfer_learn_pruned.md + 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 ``` - YOLOv5s Pruned-Quantized transfer learning: ```bash - 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.VOC.yaml --recipe ../recipes/yolov5.transfer_learn_pruned_quantized.md + 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 ``` - YOLOv5s Baseline transfer learning: ```bash - 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.VOC.yaml --epochs 50 + 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 ``` - YOLOv5l Pruned transfer learning: ```bash - 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.VOC.yaml --recipe ../recipes/yolov5.transfer_learn_pruned.md + 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 ``` - YOLOv5l Pruned-Quantized transfer learning: ```bash - 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.VOC.yaml --recipe ../recipes/yolov5.transfer_learn_pruned_quantized.md + 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 ``` - YOLOv5l Baseline transfer learning: ```bash - 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.VOC.yaml --epochs 50 + 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 ``` **_Notes About Transfer Learning_** From aa04e1527ce484f180858bc003e321ef2c2e5881 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Fri, 8 Apr 2022 09:40:40 -0400 Subject: [PATCH 4/6] Fix: nit --- integrations/ultralytics-yolov5/setup_integration.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/ultralytics-yolov5/setup_integration.sh b/integrations/ultralytics-yolov5/setup_integration.sh index e9e08254728..503bf63f630 100755 --- a/integrations/ultralytics-yolov5/setup_integration.sh +++ b/integrations/ultralytics-yolov5/setup_integration.sh @@ -8,4 +8,4 @@ git clone https://github.com/neuralmagic/yolov5.git cd yolov5 git checkout release/0.12 pip install -r requirements.txt -pip install sparseml[torch, torchvision] +pip install sparseml[torch,torchvision] From 9301193bbda5c509eca48ba2e7eb19fd9c6c4e41 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Fri, 8 Apr 2022 09:48:49 -0400 Subject: [PATCH 5/6] Fix: remove redundant sparseml install --- integrations/ultralytics-yolov5/setup_integration.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integrations/ultralytics-yolov5/setup_integration.sh b/integrations/ultralytics-yolov5/setup_integration.sh index 503bf63f630..06c5f8f3ef8 100755 --- a/integrations/ultralytics-yolov5/setup_integration.sh +++ b/integrations/ultralytics-yolov5/setup_integration.sh @@ -6,6 +6,5 @@ git clone https://github.com/neuralmagic/yolov5.git cd yolov5 -git checkout release/0.12 +git checkout update-6.1 pip install -r requirements.txt -pip install sparseml[torch,torchvision] From c94f2cc5589b054db5ecd2f153a924d523bfd968 Mon Sep 17 00:00:00 2001 From: Benjamin Fineran Date: Fri, 8 Apr 2022 14:44:43 -0400 Subject: [PATCH 6/6] point setup to release branch --- integrations/ultralytics-yolov5/setup_integration.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/ultralytics-yolov5/setup_integration.sh b/integrations/ultralytics-yolov5/setup_integration.sh index 06c5f8f3ef8..22de931ea7a 100755 --- a/integrations/ultralytics-yolov5/setup_integration.sh +++ b/integrations/ultralytics-yolov5/setup_integration.sh @@ -6,5 +6,5 @@ git clone https://github.com/neuralmagic/yolov5.git cd yolov5 -git checkout update-6.1 +git checkout release/0.12 pip install -r requirements.txt