{"id":13643130,"url":"https://github.com/SpursLipu/YOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone","last_synced_at":"2025-04-20T21:33:04.124Z","repository":{"id":37612593,"uuid":"229930064","full_name":"SpursLipu/YOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone","owner":"SpursLipu","description":"YOLO ModelCompression MultidatasetTraining","archived":false,"fork":false,"pushed_at":"2022-06-21T23:54:56.000Z","size":47566,"stargazers_count":445,"open_issues_count":41,"forks_count":136,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-09T14:42:01.832Z","etag":null,"topics":["mobilenetv3","modelcompression","multidataset","object-detection","pruning","quantization-aware-training","yolo"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SpursLipu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-24T11:31:48.000Z","updated_at":"2024-10-09T12:21:03.000Z","dependencies_parsed_at":"2022-08-18T14:50:31.505Z","dependency_job_id":null,"html_url":"https://github.com/SpursLipu/YOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpursLipu%2FYOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpursLipu%2FYOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpursLipu%2FYOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpursLipu%2FYOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpursLipu","download_url":"https://codeload.github.com/SpursLipu/YOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249965566,"owners_count":21352926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mobilenetv3","modelcompression","multidataset","object-detection","pruning","quantization-aware-training","yolo"],"created_at":"2024-08-02T01:01:42.308Z","updated_at":"2025-04-20T21:33:01.889Z","avatar_url":"https://github.com/SpursLipu.png","language":"Python","funding_links":[],"categories":["Lighter and Deployment Frameworks"],"sub_categories":[],"readme":"# YOLOv3-ModelCompression-MultidatasetTraining\n\nThis project mainly include three parts.\n\n1.Provides training methods for multiple mainstream object detection datasets(coco2017, coco2014, BDD100k, Visdrone,\nHand)\n\n2.Provides a mainstream model compression algorithm including pruning, quantization, and knowledge distillation.\n\n3.Provides multiple backbone for yolov3 including Darknet-YOLOv3，Tiny-YOLOv3，Mobilenetv3-YOLOv3\n\nSource using Pytorch implementation to [ultralytics/yolov3](https://github.com/ultralytics/yolov3) for yolov3 source\ncode. Pruning method based on BN layer\nby [coldlarry/YOLOv3-complete-pruning](https://github.com/coldlarry/YOLOv3-complete-pruning), thanks to both of you.\n\n**If you can't download weights file and datasets from BaiDu, please send e-mail(spurslipu@pku.edu.cn) to me, I will \nrely as soon as I can.**\n\n# Update\n\nJanuary 4, 2020. Provides download links and training methods to the Visdrone dataset.\n\nJanuary 19, 2020. Dior, Bdd100k and Visdrone training will be provided, as well as the converted weights file.\n\nMarch 1, 2020. Provides Mobilenetv3 backbone.\n\nApril 7, 2020. Implement two models based on Mobilenetv3: Yolov3-Mobilenet, and Yolov3tin-Mobilene-small, provide\npre-training weights, extend the normal pruning methods to the two Mobilenet-based models.\n\nApril 27, 2020. Update mobilenetv3 pre-training weights, add a layer pruning method, methods from\nthe [tanluren/yolov3-channel-and-layer-pruning/yolov3](https://github.com/tanluren/yolov3-channel-and-layer-pruning),\nThanks for sharing.\n\nMay 22, 2020. Updated some new optimizations from [ultralytics/yolov3](https://github.com/ultralytics/yolov3), update\ncfg file and weights of YOLOv4.\n\nMay 22, 2020. The 8-bit quantization method was updated and some bugs were fixed.\n\nJuly 12, 2020. The problem of mAP returning to 0 after pruning in yolov3-mobilenet was fixed. See issue#41 for more\ndetails.\n\nSeptember 30, 2020. The BN_Fold training method was updated to reduce the precision loss caused by BN fusion, and the\nPOW (2) quantization method targeted at FPGA was updated. See the quantization section for details.\n\n# Requirements\n\nOur project based on [ultralytics/yolov3](https://github.com/ultralytics/yolov3),\nsee [ultralytics/yolov3](https://github.com/ultralytics/yolov3) for details. Here is a brief explanation:\n\n- `numpy`\n- `torch \u003e= 1.1.0`\n- `opencv-python`\n- `tqdm`\n\n# Current support\n\n|\u003ccenter\u003eFunction\u003c/center\u003e|\u003ccenter\u003e\u003c/center\u003e|\n| --- |--- |\n|\u003ccenter\u003eMulti-Backbone training\u003c/center\u003e|\u003ccenter\u003e√\u003c/center\u003e  |\n|\u003ccenter\u003eMulti-Datasets\u003c/center\u003e|\u003ccenter\u003e√\u003c/center\u003e  |\n|\u003ccenter\u003ePruning\u003c/center\u003e|\u003ccenter\u003e√\u003c/center\u003e  |\n|\u003ccenter\u003eQuantization\u003c/center\u003e|\u003ccenter\u003e√\u003c/center\u003e  |\n|\u003ccenter\u003eKnowledge Distillation\u003c/center\u003e|\u003ccenter\u003e√\u003c/center\u003e  |\n\n# Training\n\n`python3 train.py --data ... --cfg ... `For training model command, the -pt command is required when using coco\npre-training model.\n\n`python3 test.py --data ... --cfg ... ` For testing model command\n\n`python3 detect.py --data ... --cfg ... --source ...` For detecting model command, the default address of source is\ndata/samples, the output result is saved in the /output, and the detection resource can be pictures and videos.\n\n# Multi-Datasets\n\nThis project provides preprocessed datasets for the YOLOv3, configuration files (.cfg), dataset index files (.data),\ndataset category files (.names), and anchor box sizes (including 9 boxes for YOLOv3 and 6 boxes for tiny- YOLOv3) that\nare reclustered using the K-means algorithm.\n\nmAP\n\n|\u003ccenter\u003eDataset\u003c/center\u003e|\u003ccenter\u003eYOLOv3-640\u003c/center\u003e|\u003ccenter\u003eYOLOv4-640\u003c/center\u003e|\u003ccenter\u003eYOLOv3-mobilenet-640\u003c/center\u003e|\n| --- |--- |--- |--- |\n|\u003ccenter\u003eDior\u003c/center\u003e|\u003ccenter\u003e0.749\u003c/center\u003e|\n|\u003ccenter\u003ebdd100k\u003c/center\u003e|\u003ccenter\u003e0.543\u003c/center\u003e|\n|\u003ccenter\u003evisdrone\u003c/center\u003e|\u003ccenter\u003e0.311\u003c/center\u003e|\u003ccenter\u003e0.383\u003c/center\u003e|\u003ccenter\u003e0.348\u003c/center\u003e|\n\nDatasets, download and unzip to /data.\n\n- [COCO2017](https://pan.baidu.com/s/1KysFL6AmdbCBq4tHDebqlw)\n\n  Extract code：hjln\n\n- [COCO2014](https://pan.baidu.com/s/1EoXOR77yEVokqPCaxg8QGg)\n\n  Extract code：rhqx\n\n- [COCO weights](https://pan.baidu.com/s/1JZylwRQIgAd389oWUu0djg)\n\n  Extract code：k8ms\n\nTraining command\n\n```bash\npython3 train.py --data data/coco2017.data --batch-size ... --weights weights/yolov3-608.weights -pt --cfg cfg/yolov3/yolov3.cfg --img-size ... --epochs ...\n```\n\n- [Dior](https://pan.baidu.com/s/1z0IQPBN16I-EctjwN9Idyg)\n\n  Extract code：vnuq\n\n- [Dior weights](https://pan.baidu.com/s/12lYOgBAo1R5VkOZqDqCFJQ)\n\n  Extract code：l8wz\n\nTraining command\n\n```bash\npython3 train.py --data data/dior.data --batch-size ... --weights weights/yolov3-608.weights -pt --cfg cfg/yolov3/yolov3-onDIOR.cfg --img-size ... --epochs ...\n```\n\n- [bdd100k](https://pan.baidu.com/s/157Md2qeFgmcOv5UmnIGI_g)\n\n  Extract code：8duw\n\n- [bdd100k weights](https://pan.baidu.com/s/1wWiHlLxIaK_WHy_mG2wmAA)\n\n  Extract code：xeqo\n\nTraining command\n\n```bash\npython3 train.py --data data/bdd100k.data --batch-size ... --weights weights/yolov3-608.weights -pt --cfg cfg/yolov3/yolov3-bdd100k.cfg --img-size ... --epochs ...\n```\n\n- [visdrone](https://pan.baidu.com/s/1CPGmS3tLI7my4_m7qDhB4Q)\n\n  Extract code：dy4c\n\n- [YOLOv3-visdrone weights](https://pan.baidu.com/s/1N4qDP3b0tt8TIWuTFefDEw)\n\n  Extract code：87lf\n\n- [YOLOv4-visdrone weights](https://pan.baidu.com/s/1zOFyt_AFiNk0fAFa8yE9RQ)\n\n  Extract code：xblu\n\n- [YOLOv3-mobilenet-visdrone weights](https://pan.baidu.com/s/1BHC8b6xHmTuN8h74QJFt1g)\n\nExtract code：fb6y\n\nTraining command\n\n```bash\npython train.py --data data/visdrone.data --batch-size ... --weights weights/yolov3-608.weights -pt --cfg cfg/yolov3/yolov3-visdrone.cfg  --img-size ... --epochs ...\n```\n\n- [oxfordhand](https://pan.baidu.com/s/1JL4gFGh-W_gYEEsiIQssZw)\n\n  Extract code：3du4\n\nTraining command\n\n```bash\npython train.py --data data/oxfordhand.data --batch-size ... --weights weights/yolov3-608.weights -pt --cfg cfg/yolov3/yolov3-hand.cfg  --img-size ... --epochs ...\n```\n\n## 1.Dior\n\nThe DIRO dataset is one of the largest, most diverse, and publicly available object detection datasets in the Earth\nobservation community. Among them, the number of instances of ships and vehicles is high, which achieves a good balance\nbetween small instances and large ones. The images were collected from Google Earth.\n\n[Introduction](https://cloud.tencent.com/developer/article/1509762)\n\n### Test results\n\n![Test results](https://github.com/SpursLipu/YOLOv3-ModelCompression-MultidatasetTraining/blob/master/image_in_readme/2.jpg)\n![Test results](https://github.com/SpursLipu/YOLOv3-ModelCompression-MultidatasetTraining/blob/master/image_in_readme/3.jpg)\n\n## 2.bdd100k\n\nBdd100 is a large, diverse data set of driving videos containing 100,000 videos. Each video was about 40 seconds long,\nand the researchers marked bounding boxes for all 100,000 key frames of objects that often appeared on the road. The\ndata set covers different weather conditions, including sunny, cloudy and rainy days, and different times of day and\nnight.\n\n[Website](http://bair.berkeley.edu/blog/2018/05/30/bdd/)\n\n[Download](http://bdd-data.berkeley.edu)\n\n[Paper](https://arxiv.org/abs/1805.04687)\n\n### Test results\n\n![Test results](https://github.com/SpursLipu/YOLOv3-ModelCompression-MultidatasetTraining/blob/master/image_in_readme/1.jpg)\n\n## 3.Visdrone\n\nThe VisDrone2019 dataset was collected by AISKYEYE team at the Machine Learning and Data Mining Laboratory at Tianjin\nUniversity, China. Benchmark data set contains 288 video clips, and consists of 261908 frames and 10209 frames a static\nimage, by all sorts of installed on the unmanned aerial vehicle (uav) camera capture, covers a wide range of aspects,\nincluding location (thousands of kilometers apart from China in 14 different cities), environment (city and country),\nobject (pedestrians, vehicles, bicycles, etc.) and density (sparse and crowded scenario). This data set was collected\nusing a variety of uav platforms (i.e., uAvs with different models) in a variety of situations and under various weather\nand light conditions. These frames are manually marked with more than 2.6 million border frames, which are often targets\nof interest, such as pedestrians, cars, bicycles and tricycles. Some important attributes are also provided, including\nscene visibility, object categories, and occlusion, to improve data utilization.\n\n[Website](http://www.aiskyeye.com/)\n\n### Test results of YOLOv3\n\n![Test results](https://github.com/SpursLipu/YOLOv3-ModelCompression-MultidatasetTraining/blob/master/image_in_readme/4.jpg)\n\n### Test results of YOLOv4\n\n![Test results](https://github.com/SpursLipu/YOLOv3-ModelCompression-MultidatasetTraining/blob/master/image_in_readme/5.jpg)\n![Test results](https://github.com/SpursLipu/YOLOv3-ModelCompression-MultidatasetTraining/blob/master/image_in_readme/6.png)\n\n# Multi-Backbone\n\nBased on mobilenetv3, two network structures are designed.\n\n|Structure |\u003ccenter\u003ebackbone\u003c/center\u003e|\u003ccenter\u003ePostprocessing\u003c/center\u003e |\u003ccenter\u003eParameters\u003c/center\u003e |\u003ccenter\u003eGFLOPS\u003c/center\u003e |\u003ccenter\u003emAP0.5\u003c/center\u003e |\u003ccenter\u003emAP0.5:0.95\u003c/center\u003e |\u003ccenter\u003espeed(inference/NMS/total)\u003c/center\u003e |\u003ccenter\u003eFPS\u003c/center\u003e |\n| --- | --- | --- | --- | --- | --- | --- | --- | --- |\n|YOLOv3                      |38.74M  |20.39M  |59.13M  |117.3   |0.580  |0.340  |12.3/1.7/14.0 ms|71.4fps  |\n|YOLOv3tiny                  |6.00M   |2.45M   |8.45M   |9.9     |0.347  |0.168  |3.5/1.8/5.3 ms  |188.7fps |\n|YOLOv3-mobilenetv3          |2.84M   |20.25M  |23.09M  |32.2    |0.547  |0.346  |7.9/1.8/9.7 ms  |103.1fps |\n|YOLOv3tiny-mobilenetv3-small|0.92M   |2.00M   |2.92M   |2.9     |0.379  |0.214  |5.2/1.9/7.1 ms  |140.8fps |\n|YOLOv4                      |-       |-       |61.35M  |107.1   |0.650  |0.438  |13.5/1.8/15.3 ms|65.4fps  |\n|YOLOv4-tiny                 |-       |-       |5.78M   |12.3    |0.435  |0.225  |4.1/1.7/5.8 ms  |172.4fps |\n\n1. YOLOv3,YOLOv3tiny and YOLOv4 were trained and tested on coco2014, and Yolov3-Mobilenetv3 and YOLOv3tiny\n   Mobilenetv3-Small were trained and tested on coco2017.\n\n2. The inference speed test on GTX2080ti*4, and image size is 608.\n\n3. The training set should match the testing set, because mismatch will cause the mistakes of mAP.\n   Read [issue](https://github.com/ultralytics/yolov3/issues/970) for detial.\n\n## Train command\n\n1.YOLOv3\n\n```bash\npython3 train.py --data data/... --batch-size ... -pt --weights weights/yolov3-608.weights --cfg cfg/yolov3/yolov3.cfg --img_size ...\n```\n\nWeights Download\n\n- [COCO pretraining weights](https://pan.baidu.com/s/1JZylwRQIgAd389oWUu0djg)\n\n  Extract code：k8ms\n\n2.YOLOv3tiny\n\n```bash\npython3 train.py --data data/... --batch-size ... -pt --weights weights/yolov3tiny.weights --cfg cfg/yolov3tiny/yolov3-tiny.cfg --img_size ...\n```\n\n- [COCO pretraining weights](https://pan.baidu.com/s/1iWGxdjR3TWxEe37__msyRA)\n\n  Extract code：udfe\n\n3.YOLOv3tiny-mobilenet-small\n\n```bash\npython3 train.py --data data/... --batch-size ... -pt --weights weights/yolov3tiny-mobilenet-small.weights --cfg cfg/yolov3tiny-mobilenet-small/yolov3tiny-mobilenet-small-coco.cfg --img_size ...\n```\n\n- [COCO pretraining weights](https://pan.baidu.com/s/1mSFjWLU91H2OhNemsAeiiQ)\n\n  Extract code：pxz4\n\n4.YOLOv3-mobilenet\n\n```bash\npython3 train.py --data data/... --batch-size ... -pt --weights weights/yolov3-mobilenet.weights --cfg cfg/yolov3-mobilenet/yolov3-mobilenet-coco.cfg --img_size ...\n```\n\n- [COCO pretraining weights](https://pan.baidu.com/s/1EI2Xh1i18CRLoZo_P3NVHw)\n\n  Extract code：3vm8\n\n5.YOLOv4\n\n```bash\npython3 train.py --data data/... --batch-size ... -pt --weights weights/yolov4.weights --cfg cfg/yolov4/yolov4.cfg --img_size ...\n```\n\n- [COCO pretraining weights](https://pan.baidu.com/s/1jAGNNC19oQhAIgBfUrkzmQ)\n\n  Extract code：njdg\n\n# Model Compression\n\n## 1. Pruning\n\n### Features\n\n|\u003ccenter\u003emethod\u003c/center\u003e |\u003ccenter\u003eadvantage\u003c/center\u003e|\u003ccenter\u003edisadvantage\u003c/center\u003e |\n| --- | --- | --- |\n|Normal pruning        |Not prune for shortcut layer. It has a considerable and stable compression rate but requires no fine tuning.|The compression rate is limited.  |\n|Shortcut pruning      |Very high compression rate.  |Fine-tuning is necessary.  |\n|Silmming              |Shortcut fusion method is used to improve the precision of shear planting.|Best way for shortcut pruning|\n|Regular pruning       |Designed for hardware deployment, the number of filters after pruning is a multiple of 2, no fine-tuning, support tiny-yolov3 and Mobilenet.|Part of the compression ratio is sacrificed for regularization. |\n|layer pruning         |ResBlock is used as the basic unit for purning, which is conducive to hardware deployment. |It can only cut backbone. |\n|layer-channel pruning |First, use channel pruning and then use layer pruning, and pruning rate was very high. |Accuracy may be affected. |\n\n### Step\n\n1.Training\n\n```bash\npython3 train.py --data ... -pt --batch-size ... --weights ... --cfg ...\n```\n\n2.Sparse training\n\n`--s`Specifies the sparsity factor，`--prune`Specify the sparsity type.\n\n`--prune 0` is the sparsity of normal pruning and regular pruning.\n\n`--prune 1` is the sparsity of shortcut pruning.\n\n`--prune 2` is the sparsity of layer pruning.\n\ncommand：\n\n```bash\npython3 train.py --data ... -pt --batch-size 32  --weights ... --cfg ... --s 0.001 --prune 0 \n```\n\n3.Pruning\n\n- normal pruning\n\n```bash\npython3 normal_prune.py --cfg ... --data ... --weights ... --percent ...\n```\n\n- regular pruning\n\n```bash\npython3 regular_prune.py --cfg ... --data ... --weights ... --percent ...\n```\n\n- shortcut pruning\n\n```bash\npython3 shortcut_prune.py --cfg ... --data ... --weights ... --percent ...\n```\n\n- silmming\n\n```bash\npython3 slim_prune.py --cfg ... --data ... --weights ... --percent ...\n```\n\n- layer pruning\n\n```bash\npython3 layer_prune.py --cfg ... --data ... --weights ... --shortcut ...\n```\n\n- layer-channel pruning\n\n```bash\npython3 layer_channel_prune.py --cfg ... --data ... --weights ... --shortcut ... --percent ...\n```\n\nIt is important to note that the cfg and weights variables in OPT need to be pointed to the cfg and weights files\ngenerated by step 2.\n\nIn addition, you can get more compression by increasing the percent value in the code.\n(If the sparsity is not enough and the percent value is too high, the program will report an error.)\n\n### Pruning experiment\n\n1.normal pruning oxfordhand，img_size = 608，test on GTX2080Ti*4\n\n|\u003ccenter\u003emodel\u003c/center\u003e |\u003ccenter\u003eparameter before pruning\u003c/center\u003e |\u003ccenter\u003emAP before pruning\u003c/center\u003e|\u003ccenter\u003einference time before pruning\u003c/center\u003e|\u003ccenter\u003epercent\u003c/center\u003e |\u003ccenter\u003eparameter after pruning\u003c/center\u003e |\u003ccenter\u003emAP after pruning\u003c/center\u003e |\u003ccenter\u003einference time after pruning\u003c/center\u003e\n| --- | --- | --- | --- | --- | --- | --- | --- |\n|yolov3(without fine tuning)     |58.67M   |0.806   |0.1139s   |0.8    |10.32M |0.802 |0.0844s |\n|yolov3-mobilenet(fine tuning)   |22.75M   |0.812   |0.0345s   |0.97   |2.72M  |0.795 |0.0211s |\n|yolov3tiny(fine tuning)         |8.27M    |0.708   |0.0144s   |0.5    |1.13M  |0.641 |0.0116s |\n\n2.regular pruning oxfordhand，img_size = 608，test ong GTX2080Ti*4\n\n|\u003ccenter\u003emodel\u003c/center\u003e |\u003ccenter\u003eparameter before pruning\u003c/center\u003e |\u003ccenter\u003emAP before pruning\u003c/center\u003e|\u003ccenter\u003einference time before pruning\u003c/center\u003e|\u003ccenter\u003epercent\u003c/center\u003e |\u003ccenter\u003eparameter after pruning\u003c/center\u003e |\u003ccenter\u003emAP after pruning\u003c/center\u003e |\u003ccenter\u003einference time after pruning\u003c/center\u003e\n| --- | --- | --- | --- | --- | --- | --- | --- |\n|yolov3(without fine tuning)           |58.67M   |0.806   |0.1139s   |0.8    |12.15M |0.805 |0.0874s |\n|yolov3-mobilenet(fine tuning)   |22.75M   |0.812   |0.0345s   |0.97   |2.75M  |0.803 |0.0208s |\n|yolov3tiny(fine tuning)         |8.27M    |0.708   |0.0144s   |0.5    |1.82M  |0.703 |0.0122s |\n\n3.shortcut pruning oxfordhand，img_size = 608，test ong GTX2080Ti*4\n\n|\u003ccenter\u003emodel\u003c/center\u003e |\u003ccenter\u003eparameter before pruning\u003c/center\u003e |\u003ccenter\u003emAP before pruning\u003c/center\u003e|\u003ccenter\u003einference time before pruning\u003c/center\u003e|\u003ccenter\u003epercent\u003c/center\u003e |\u003ccenter\u003eparameter after pruning\u003c/center\u003e |\u003ccenter\u003emAP after pruning\u003c/center\u003e |\u003ccenter\u003einference time after pruning\u003c/center\u003e\n| --- | --- | --- | --- | --- | --- | --- | --- |\n|yolov3           |58.67M   |0.806   |   |0.8    |6.35M  |0.816 | |\n|yolov4           |60.94M   |0.896   |   |0.6    |13.97M |0.855 | |\n\n## 2.quantization\n\n`--quantized 2` Dorefa quantization method\n\n```bash\npython train.py --data ... --batch-size ... --weights ... --cfg ... --img-size ... --epochs ... --quantized 2\n```\n\n`--quantized 1` Google quantization method\n\n```bash\npython train.py --data ... --batch-size ... --weights ... --cfg ... --img-size ... --epochs ... --quantized 1\n```\n\n`--FPGA` Pow(2) quantization for FPGA.\n\n### experiment\n\noxfordhand, yolov3, 640image-size\n\n|\u003ccenter\u003emethod\u003c/center\u003e |\u003ccenter\u003emAP\u003c/center\u003e |\n| --- | --- |\n|Baseline                     |0.847    |\n|Google8bit                   |0.851    |\n|Google8bit + BN Flod         |0.851    |\n|Google8bit + BN Flod + FPGA  |0.852    |\n|Google4bit + BN Flod + FPGA  |0.842    |\n\n## 3.Knowledge Distillation\n\n### Knowledge Distillation\n\nThe distillation method is based on the basic distillation method proposed by Hinton in 2015, and has been partially\nimproved in combination with the detection network.\n\nDistilling the Knowledge in a Neural Network\n[paper](https://arxiv.org/abs/1503.02531)\n\ncommand : `--t_cfg --t_weights --KDstr`\n\n`--t_cfg` cfg file of teacher model\n\n`--t_weights` weights file of teacher model\n\n`--KDstr` KD strategy\n\n    `--KDstr 1` KLloss can be obtained directly from the output of teacher network and the output of student network and added to the overall loss.\n    `--KDstr 2` To distinguish between box loss and class loss, the student does not learn directly from the teacher. L2 distance is calculated respectively for student, teacher and GT. When student is greater than teacher, an additional loss is added for student and GT.\n    `--KDstr 3` To distinguish between Boxloss and ClassLoss, the student learns directly from the teacher.\n    `--KDstr 4` KDloss is divided into three categories, box loss, class loss and feature loss.\n    `--KDstr 5` On the basis of KDstr 4, the fine-grain-mask is added into the feature\n\nexample:\n\n```bash\npython train.py --data ... --batch-size ... --weights ... --cfg ... --img-size ... --epochs ... --t_cfg ... --t_weights ...\n```\n\nUsually, the pre-compression model is used as the teacher model, and the post-compression model is used as the student\nmodel for distillation training to improve the mAP of student network.\n\n### experiment\n\noxfordhand，yolov3tiny as teacher model，normal pruning yolov3tiny as student model\n\n|\u003ccenter\u003eteacher model\u003c/center\u003e |\u003ccenter\u003emAP of teacher model\u003c/center\u003e |\u003ccenter\u003estudent model\u003c/center\u003e|\u003ccenter\u003edirectly fine tuning\u003c/center\u003e|\u003ccenter\u003eKDstr 1\u003c/center\u003e |\u003ccenter\u003eKDstr 2\u003c/center\u003e |\u003ccenter\u003eKDstr 3\u003c/center\u003e  |\u003ccenter\u003eKDstr 4(L1)\u003c/center\u003e |\u003ccenter\u003eKDstr 5(L1)\u003c/center\u003e |\n| --- | --- | --- | --- | --- | --- | --- |--- |--- |\n|yolov3tiny608   |0.708    |normal pruning yolov3tiny608    |0.658     |0.666    |0.661  |0.672   |0.673   |0.674   |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSpursLipu%2FYOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSpursLipu%2FYOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSpursLipu%2FYOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone/lists"}