{"id":13545499,"url":"https://github.com/hunglc007/tensorflow-yolov4-tflite","last_synced_at":"2025-05-14T22:08:36.742Z","repository":{"id":37545379,"uuid":"258479275","full_name":"hunglc007/tensorflow-yolov4-tflite","owner":"hunglc007","description":"YOLOv4, YOLOv4-tiny, YOLOv3, YOLOv3-tiny Implemented in Tensorflow 2.0, Android. Convert YOLO v4 .weights tensorflow, tensorrt and tflite","archived":false,"fork":false,"pushed_at":"2024-05-12T16:19:31.000Z","size":202388,"stargazers_count":2256,"open_issues_count":316,"forks_count":1236,"subscribers_count":43,"default_branch":"master","last_synced_at":"2025-04-13T18:44:38.565Z","etag":null,"topics":["android","object-detection","tensorflow","tensorrt","tf2","tflite","yolov3","yolov3-tiny","yolov4"],"latest_commit_sha":null,"homepage":"https://github.com/hunglc007/tensorflow-yolov4-tflite","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hunglc007.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-24T10:22:52.000Z","updated_at":"2025-04-12T02:30:10.000Z","dependencies_parsed_at":"2024-10-14T19:12:12.616Z","dependency_job_id":null,"html_url":"https://github.com/hunglc007/tensorflow-yolov4-tflite","commit_stats":{"total_commits":134,"total_committers":13,"mean_commits":"10.307692307692308","dds":"0.33582089552238803","last_synced_commit":"9f16748aa3f45ff240608da4bd9b1216a29127f5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunglc007%2Ftensorflow-yolov4-tflite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunglc007%2Ftensorflow-yolov4-tflite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunglc007%2Ftensorflow-yolov4-tflite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hunglc007%2Ftensorflow-yolov4-tflite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hunglc007","download_url":"https://codeload.github.com/hunglc007/tensorflow-yolov4-tflite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235700,"owners_count":22036964,"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":["android","object-detection","tensorflow","tensorrt","tf2","tflite","yolov3","yolov3-tiny","yolov4"],"created_at":"2024-08-01T11:01:04.181Z","updated_at":"2025-05-14T22:08:31.720Z","avatar_url":"https://github.com/hunglc007.png","language":"Python","funding_links":[],"categories":["Python","Other Versions of YOLO","TensorFlow Models"],"sub_categories":["Computer Vision"],"readme":"# tensorflow-yolov4-tflite\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)\n\nYOLOv4, YOLOv4-tiny Implemented in Tensorflow 2.0. \nConvert YOLO v4, YOLOv3, YOLO tiny .weights to .pb, .tflite and trt format for tensorflow, tensorflow lite, tensorRT.\n\nDownload yolov4.weights file: https://drive.google.com/open?id=1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT\n\n\n### Prerequisites\n* Tensorflow 2.3.0rc0\n\n### Performance\n\u003cp align=\"center\"\u003e\u003cimg src=\"data/performance.png\" width=\"640\"\\\u003e\u003c/p\u003e\n\n### Demo\n\n```bash\n# Convert darknet weights to tensorflow\n## yolov4\npython save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 \n\n## yolov4-tiny\npython save_model.py --weights ./data/yolov4-tiny.weights --output ./checkpoints/yolov4-tiny-416 --input_size 416 --model yolov4 --tiny\n\n# Run demo tensorflow\npython detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --image ./data/kite.jpg\n\npython detect.py --weights ./checkpoints/yolov4-tiny-416 --size 416 --model yolov4 --image ./data/kite.jpg --tiny\n\n```\nIf you want to run yolov3 or yolov3-tiny change ``--model yolov3`` in command\n\n#### Output\n\n##### Yolov4 original weight\n\u003cp align=\"center\"\u003e\u003cimg src=\"result.png\" width=\"640\"\\\u003e\u003c/p\u003e\n\n##### Yolov4 tflite int8\n\u003cp align=\"center\"\u003e\u003cimg src=\"result-int8.png\" width=\"640\"\\\u003e\u003c/p\u003e\n\n### Convert to tflite\n\n```bash\n# Save tf model for tflite converting\npython save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite\n\n# yolov4\npython convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite\n\n# yolov4 quantize float16\npython convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-fp16.tflite --quantize_mode float16\n\n# yolov4 quantize int8\npython convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-int8.tflite --quantize_mode int8 --dataset ./coco_dataset/coco/val207.txt\n\n# Run demo tflite model\npython detect.py --weights ./checkpoints/yolov4-416.tflite --size 416 --model yolov4 --image ./data/kite.jpg --framework tflite\n```\nYolov4 and Yolov4-tiny int8 quantization have some issues. I will try to fix that. You can try Yolov3 and Yolov3-tiny int8 quantization \n### Convert to TensorRT\n```bash# yolov3\npython save_model.py --weights ./data/yolov3.weights --output ./checkpoints/yolov3.tf --input_size 416 --model yolov3\npython convert_trt.py --weights ./checkpoints/yolov3.tf --quantize_mode float16 --output ./checkpoints/yolov3-trt-fp16-416\n\n# yolov3-tiny\npython save_model.py --weights ./data/yolov3-tiny.weights --output ./checkpoints/yolov3-tiny.tf --input_size 416 --tiny\npython convert_trt.py --weights ./checkpoints/yolov3-tiny.tf --quantize_mode float16 --output ./checkpoints/yolov3-tiny-trt-fp16-416\n\n# yolov4\npython save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4.tf --input_size 416 --model yolov4\npython convert_trt.py --weights ./checkpoints/yolov4.tf --quantize_mode float16 --output ./checkpoints/yolov4-trt-fp16-416\n```\n\n### Evaluate on COCO 2017 Dataset\n```bash\n# run script in /script/get_coco_dataset_2017.sh to download COCO 2017 Dataset\n# preprocess coco dataset\ncd data\nmkdir dataset\ncd ..\ncd scripts\npython coco_convert.py --input ./coco/annotations/instances_val2017.json --output val2017.pkl\npython coco_annotation.py --coco_path ./coco \ncd ..\n\n# evaluate yolov4 model\npython evaluate.py --weights ./data/yolov4.weights\ncd mAP/extra\npython remove_space.py\ncd ..\npython main.py --output results_yolov4_tf\n```\n#### mAP50 on COCO 2017 Dataset\n\n| Detection   | 512x512 | 416x416 | 320x320 |\n|-------------|---------|---------|---------|\n| YoloV3      | 55.43   | 52.32   |         |\n| YoloV4      | 61.96   | 57.33   |         |\n\n### Benchmark\n```bash\npython benchmarks.py --size 416 --model yolov4 --weights ./data/yolov4.weights\n```\n#### TensorRT performance\n \n| YoloV4 416 images/s |   FP32   |   FP16   |   INT8   |\n|---------------------|----------|----------|----------|\n| Batch size 1        | 55       | 116      |          |\n| Batch size 8        | 70       | 152      |          |\n\n#### Tesla P100\n\n| Detection   | 512x512 | 416x416 | 320x320 |\n|-------------|---------|---------|---------|\n| YoloV3 FPS  | 40.6    | 49.4    | 61.3    |\n| YoloV4 FPS  | 33.4    | 41.7    | 50.0    |\n\n#### Tesla K80\n\n| Detection   | 512x512 | 416x416 | 320x320 |\n|-------------|---------|---------|---------|\n| YoloV3 FPS  | 10.8    | 12.9    | 17.6    |\n| YoloV4 FPS  | 9.6     | 11.7    | 16.0    |\n\n#### Tesla T4\n\n| Detection   | 512x512 | 416x416 | 320x320 |\n|-------------|---------|---------|---------|\n| YoloV3 FPS  | 27.6    | 32.3    | 45.1    |\n| YoloV4 FPS  | 24.0    | 30.3    | 40.1    |\n\n#### Tesla P4\n\n| Detection   | 512x512 | 416x416 | 320x320 |\n|-------------|---------|---------|---------|\n| YoloV3 FPS  | 20.2    | 24.2    | 31.2    |\n| YoloV4 FPS  | 16.2    | 20.2    | 26.5    |\n\n#### Macbook Pro 15 (2.3GHz i7)\n\n| Detection   | 512x512 | 416x416 | 320x320 |\n|-------------|---------|---------|---------|\n| YoloV3 FPS  |         |         |         |\n| YoloV4 FPS  |         |         |         |\n\n### Traning your own model\n```bash\n# Prepare your dataset\n# If you want to train from scratch:\nIn config.py set FISRT_STAGE_EPOCHS=0 \n# Run script:\npython train.py\n\n# Transfer learning: \npython train.py --weights ./data/yolov4.weights\n```\nThe training performance is not fully reproduced yet, so I recommended to use Alex's [Darknet](https://github.com/AlexeyAB/darknet) to train your own data, then convert the .weights to tensorflow or tflite.\n\n\n\n### TODO\n* [x] Convert YOLOv4 to TensorRT\n* [x] YOLOv4 tflite on android\n* [ ] YOLOv4 tflite on ios\n* [x] Training code\n* [x] Update scale xy\n* [ ] ciou\n* [ ] Mosaic data augmentation\n* [x] Mish activation\n* [x] yolov4 tflite version\n* [x] yolov4 in8 tflite version for mobile\n\n### References\n\n  * YOLOv4: Optimal Speed and Accuracy of Object Detection [YOLOv4](https://arxiv.org/abs/2004.10934).\n  * [darknet](https://github.com/AlexeyAB/darknet)\n  \n   My project is inspired by these previous fantastic YOLOv3 implementations:\n  * [Yolov3 tensorflow](https://github.com/YunYang1994/tensorflow-yolov3)\n  * [Yolov3 tf2](https://github.com/zzh8829/yolov3-tf2)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhunglc007%2Ftensorflow-yolov4-tflite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhunglc007%2Ftensorflow-yolov4-tflite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhunglc007%2Ftensorflow-yolov4-tflite/lists"}