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

Commit d471c19

Browse files
authored
Yolo benchmarking (#108)
* Benchmarking for YOLOv3 * edits from Jeannie * support for other inference backends, updates to preprocecssing flow, quantized inputs, etc * load data from sparsezoo, ORT batch override, ORT num cores override, documentation update * qat bug fix
1 parent e05f2cb commit d471c19

File tree

8 files changed

+624
-105
lines changed

8 files changed

+624
-105
lines changed

integrations/ultralytics/README.md

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This directory provides a SparseML integrated training script for the popular
2020
repository.
2121

2222
Using this integration, you will be able to apply SparseML optimizations
23-
to the powerful training flows provided in the yolov5 repository.
23+
to the powerful training flows provided in the `yolov5` repository.
2424

2525
Some of the tasks you can perform using this integration include, but are not limited to:
2626
* model pruning
@@ -30,27 +30,29 @@ Some of the tasks you can perform using this integration include, but are not li
3030

3131
## Installation
3232
To use the script, clone both repositories, install their dependencies,
33-
and copy the integrated training script into the yolov5 directory to run from.
33+
and copy the integrated training script into the `yolov5` directory to run from.
3434

3535
```bash
3636
# clone
3737
git clone https://github.com/ultralytics/yolov5.git
3838
git clone https://github.com/neuralmagic/sparseml.git
3939

4040
# copy script
41-
cp sparseml/integrations/ultralytics/train.py sparseml/integrations/ultralytics/test.py yolov5
4241
cd yolov5
42+
git checkout c9bda11 # latest tested integration commit hash
43+
cp ../sparseml/integrations/ultralytics/*.py yolov5
44+
cp ../sparseml/integrations/ultralytics/deepsparse/*.py
4345

4446
# install dependencies
4547
pip install -r requirements.txt
46-
pip install sparseml
48+
pip install sparseml deepsparse
4749
```
4850

4951

5052
## Script
5153
`integrations/ultralytics/train.py` modifies
5254
[`train.py`](https://github.com/ultralytics/yolov5/blob/master/train.py)
53-
from yolov5 to include a `sparseml-recipe` argument
55+
from `yolov5` to include a `sparseml-recipe` argument
5456
to run SparseML optimizations with. This can be a file path to a local
5557
SparseML recipe or a SparseZoo model stub prefixed by `zoo:` such as
5658
`zoo:cv/detection/yolo_v3-spp/pytorch/ultralytics/coco/pruned-aggressive`.
@@ -61,13 +63,13 @@ initial checkpoint, pass that model's SparseZoo stub prefixed by `zoo:` to the
6163
`--initial-checkpoint` argument.
6264

6365
Running the script will
64-
follow the normal yolov5 training flow with the given SparseML optimizations enabled.
66+
follow the normal `yolov5` training flow with the given SparseML optimizations enabled.
6567

6668
Some considerations:
6769

6870
* `--sparseml-recipe` is a required parameter
6971
* `--epochs` will now be overridden by the epochs set in the SparseML recipe
70-
* if using learning rate schedulers both with the yolov5 script and your recipe, they
72+
* if using learning rate schedulers both with the `yolov5` script and your recipe, they
7173
may conflict with each other causing unintended side effects, so choose
7274
hyperparameters accordingly
7375
* Modifiers will log their outputs to the console as well as to the TensorBoard file
@@ -102,6 +104,39 @@ python train.py \
102104
```
103105

104106

105-
## Server
106-
The `server/` directory contians an self-documented example of deploying a sparsified
107-
Yolo model with the DeepSparse engine.
107+
## DeepSparse Examples
108+
The [DeepSparse](https://github.com/neuralmagic/deepsparse) engine can be used for effcient
109+
inference on sparsified YOLOv3 models. The `deepsparse` directory contains examples of using
110+
DeepSparse for benchmarking performance and in an inference server environment.
111+
112+
### Installation
113+
To use these examples after performing the previous installations, copy over the python files
114+
to the `yolov5` directory and install DeepSparse.
115+
116+
```bash
117+
# copy DeepSparse python files
118+
cp sparseml/integrations/ultralytics/deepsparse/*.py yolov5
119+
cd yolov5
120+
121+
# install deepsparse and server dependencies
122+
pip install deepsparse flask flask-cors
123+
```
124+
125+
126+
### Benchmarking
127+
`benchmarking.py` is a script for benchmarking sparsified and quantized YOLOv3
128+
performance with DeepSparse. For a full list of options run `python benchmarking.py -h`.
129+
130+
To run a benchmark run:
131+
```bash
132+
python benchmark.py
133+
zoo:cv/detection/yolo_v3-spp/pytorch/ultralytics/coco/pruned_quant-aggressive_90 \
134+
--batch-size 32 \
135+
--quantized-inputs
136+
```
137+
138+
Note for quantized performance, your CPU must support VNNI instructions.
139+
140+
### Server
141+
`sparseml/integrations/ultralytics/deepsparse/SERVER.md` contains relevant
142+
documentation for running the server and client examples.

integrations/ultralytics/server/README.md renamed to integrations/ultralytics/deepsparse/SERVER.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
1616

17-
# Example Yolo Model Server and Client Using DeepSparse Flask
17+
# Example YOLO Model Server and Client Using DeepSparse Flask
1818

19-
To illustrate how the DeepSparse engine can be used for Yolo model deployments, this directory
19+
To illustrate how the DeepSparse engine can be used for YOLO model deployments, this directory
2020
contains a sample model server and client.
2121

2222
The server uses Flask to create an app with the DeepSparse Engine hosting a
23-
compiled Yolo model.
23+
compiled YOLOv3 model.
2424
The client can make requests into the server returning object detection results for given images.
2525

2626

@@ -36,13 +36,13 @@ If both repositories are already cloned, you may skip that step.
3636
git clone https://github.com/ultralytics/yolov5.git
3737
git clone https://github.com/neuralmagic/sparseml.git
3838

39-
# copy script
40-
cp sparseml/integrations/ultralytics/server/*.py yolov5
39+
# copy DeepSparse python files
40+
cp sparseml/integrations/ultralytics/deepsparse/*.py yolov5
4141
cd yolov5
4242

4343
# install dependencies
4444
pip install -r requirements.txt
45-
pip install deepsparse flask flask-cors
45+
pip install deepsparse sparseml flask flask-cors
4646
```
4747

4848
## Execution

0 commit comments

Comments
 (0)