Skip to content

thangnx183/pruned-yolov5-tfjs

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Redundant feature pruning with yolov5

This repo extend the work from paper 'Redundant Feature Pruning for Accelerated Inference in Deep Neural Networks' Babajide O. Ayindea, Tamer Inanca, Jacek M. Zuradaa.
Contribution of this work:

  • apply proposed pruning method from paper for all yolov5 layer
  • fine-tuned pruned model to regain accuracy (in my case, pruned half parameters of yolov5n without losing in accuracy)
  • custom Tensorflowjs class to deploy on web: seprate nms module from model graph and execute in cpu for faster inference
  • end2end pipeline from train - prune - finetune - convert and post training quantization tfjs - deploy tfjs

Pruning

python channel_prune.py --weight_path path/to/checkpoint --pruned_weight_path path/to/output/checkpoint --thres 0.5
  • Specify model checkpoint, output of purned model in weigth_path and pruned_weight_path
  • Specify cosin similarity distance threshold. The higher threshold the more filter weights are pruned

Finetune to regain accuracy

python fine-tune.py --batch-size 144 --img 320 --data data/coco-old-cp.yaml --hyp data/hyps/hyp.scratch-high.yaml --weights runs/train/carpart-add-car-v2-anchor-tune-3-s-model-od/weights/best-prune-066.pt --sync-bn --device 2 --name prune-66-finetune-carpart-add-car-v2-anchor-tune-3-od-od
  • Load pruned model checkpoint as pretrain and retrain model on same dataset

Convert to TensorflowJs

python export.py --weight path/to/pruned/checkpoint --int8 --includes tfjs

Custom Yolov5js

  • Move NMS separate from model graph, nms will excecute by cpu for faster inference (detail)
  • Link demo : here

About

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 96.7%
  • TypeScript 1.4%
  • Shell 1.0%
  • Dockerfile 0.4%
  • HTML 0.2%
  • JavaScript 0.2%
  • CSS 0.1%