Skip to content

Commit

Permalink
add quantized model
Browse files Browse the repository at this point in the history
  • Loading branch information
dnth committed Jun 12, 2022
1 parent c8e7046 commit a096cf5
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 71 deletions.
74 changes: 3 additions & 71 deletions recipes/yolov5s.quantized.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,17 @@
<!--
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

---
# General Hyperparams
num_epochs: &num_epochs 302
init_lr: &init_lr 0.01
final_lr: &final_lr 0.002
weights_warmup_lr: &weights_warmup_lr 0
biases_warmup_lr: &biases_warmup_lr 0.1
num_epochs: &num_epochs 2
quantization_lr: &quantization_lr 0.000002


# Quantization Params
quantization_start_epoch: &quantization_start_epoch 300
quantization_start_epoch: &quantization_start_epoch 0

training_modifiers:
- !EpochRangeModifier
start_epoch: 0
end_epoch: *num_epochs

- !LearningRateFunctionModifier
start_epoch: 3
end_epoch: *num_epochs
lr_func: cosine
init_lr: *init_lr
final_lr: *final_lr

- !LearningRateFunctionModifier
start_epoch: 0
end_epoch: 3
lr_func: linear
init_lr: *weights_warmup_lr
final_lr: *init_lr
param_groups: [0, 1]

- !LearningRateFunctionModifier
start_epoch: 0
end_epoch: 3
lr_func: linear
init_lr: *biases_warmup_lr
final_lr: *init_lr
param_groups: [2]

- !SetLearningRateModifier
start_epoch: *quantization_start_epoch
learning_rate: *quantization_lr
Expand All @@ -64,29 +21,4 @@ quantization_modifiers:
- !QuantizationModifier
start_epoch: *quantization_start_epoch
submodules: [ 'model.0', 'model.1', 'model.2', 'model.3', 'model.4', 'model.5', 'model.6', 'model.7', 'model.8', 'model.9', 'model.10', 'model.11', 'model.12', 'model.13', 'model.14', 'model.15', 'model.16', 'model.17', 'model.18', 'model.19', 'model.20', 'model.21', 'model.22', 'model.23' ]
---

# YOLOv5s Pruned Quantized

This recipe creates a sparse, [YOLOv5s](https://github.com/ultralytics/yolov5) model that achieves 94% recovery of its baseline accuracy on the COCO dataset (0.556 mAP@0.5 baseline vs 0.525 mAP@0.5 for this recipe).
Training was done using 4 GPUs at half precision with a total batch size of 256 using the [SparseML integration with ultralytics/yolov5](https://github.com/neuralmagic/sparseml/tree/main/integrations/ultralytics-yolov5).

When running, adjust hyperparameters based on training environment and dataset.

## Training

To set up the training environment, follow the instructions on the [integration README](https://github.com/neuralmagic/sparseml/blob/main/integrations/ultralytics-yolov5/README.md).
Using the given training script from the `yolov5` directory the following command can be used to launch this recipe.
Adjust the script command for your GPU device setup.
Ultralytics supports both DataParallel and DDP.

*script command:*

```
python train.py \
--cfg ../models/yolov5s.yaml \
--weights PRETRAINED_WEIGHTS \
--data coco.yaml \
--hyp data/hyp.scratch.yaml \
--recipe ../recipes/yolov5s.pruned_quantized.md \
```
---
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions yolov5-train/yolov5-deepsparse/yolov5s-sgd-quantized/hyp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
lr0: 0.01
lrf: 0.2
momentum: 0.937
weight_decay: 0.0005
warmup_epochs: 3.0
warmup_momentum: 0.8
warmup_bias_lr: 0.1
box: 0.05
cls: 0.5
cls_pw: 1.0
obj: 1.0
obj_pw: 1.0
iou_t: 0.2
anchor_t: 4.0
fl_gamma: 0.0
hsv_h: 0.015
hsv_s: 0.7
hsv_v: 0.4
degrees: 0.0
translate: 0.1
scale: 0.5
shear: 0.0
perspective: 0.0
flipud: 0.0
fliplr: 0.5
mosaic: 1.0
mixup: 0.0
copy_paste: 0.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions yolov5-train/yolov5-deepsparse/yolov5s-sgd-quantized/opt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
weights: yolov5-deepsparse/yolov5s-sgd/weights/best.pt
cfg: ./models_v5.0/yolov5s.yaml
data: /home/dnth/Desktop/yolov5-deepsparse-blogpost/yolov5-train/data/pistols.yaml
hyp: data/hyps/hyp.scratch.yaml
epochs: 300
batch_size: 64
imgsz: 416
rect: false
resume: false
nosave: false
noval: false
noautoanchor: false
evolve: null
bucket: ''
cache: null
image_weights: false
device: ''
multi_scale: false
single_cls: false
optimizer: SGD
sync_bn: false
workers: 8
project: yolov5-deepsparse
name: yolov5s-sgd-quantized
exist_ok: false
quad: false
cos_lr: false
label_smoothing: 0.0
patience: 100
freeze:
- 0
save_period: -1
local_rank: -1
entity: null
upload_dataset: false
bbox_interval: -1
artifact_alias: latest
recipe: ../recipes/yolov5s.quantized.md
disable_ema: false
max_train_steps: -1
max_eval_steps: -1
one_shot: false
num_export_samples: 0
save_dir: yolov5-deepsparse/yolov5s-sgd-quantized2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
epoch, train/box_loss, train/obj_loss, train/cls_loss, metrics/precision, metrics/recall, metrics/mAP_0.5,metrics/mAP_0.5:0.95, val/box_loss, val/obj_loss, val/cls_loss, x/lr0, x/lr1, x/lr2
0, 0.017206, 0.0087093, 0, 0.85351, 0.78803, 0.83145, 0.51715, 0.038543, 0.0084712, 0, 2e-06, 2e-06, 2e-06
1, 0.017049, 0.0087496, 0, 0.86435, 0.78422, 0.83391, 0.52026, 0.03854, 0.0084568, 0, 2e-06, 2e-06, 2e-06
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit a096cf5

Please sign in to comment.