{"id":13642477,"url":"https://github.com/theAIGuysCode/yolov4-deepsort","last_synced_at":"2025-04-20T16:32:43.369Z","repository":{"id":37423214,"uuid":"287975205","full_name":"theAIGuysCode/yolov4-deepsort","owner":"theAIGuysCode","description":"Object tracking implemented with YOLOv4, DeepSort, and TensorFlow.","archived":false,"fork":false,"pushed_at":"2024-05-22T14:55:43.000Z","size":78683,"stargazers_count":1309,"open_issues_count":132,"forks_count":750,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-08-03T01:26:34.825Z","etag":null,"topics":["deep-sort","object-detection","object-tracker","object-tracking","tensorflow","yolov4","yolov4-deepsort"],"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/theAIGuysCode.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":"2020-08-16T15:51:50.000Z","updated_at":"2024-08-01T06:32:33.000Z","dependencies_parsed_at":"2022-08-08T20:15:45.609Z","dependency_job_id":null,"html_url":"https://github.com/theAIGuysCode/yolov4-deepsort","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/theAIGuysCode%2Fyolov4-deepsort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theAIGuysCode%2Fyolov4-deepsort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theAIGuysCode%2Fyolov4-deepsort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theAIGuysCode%2Fyolov4-deepsort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theAIGuysCode","download_url":"https://codeload.github.com/theAIGuysCode/yolov4-deepsort/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223833129,"owners_count":17210787,"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":["deep-sort","object-detection","object-tracker","object-tracking","tensorflow","yolov4","yolov4-deepsort"],"created_at":"2024-08-02T01:01:31.895Z","updated_at":"2025-04-20T16:32:43.363Z","avatar_url":"https://github.com/theAIGuysCode.png","language":"Python","funding_links":[],"categories":["Other Versions of YOLO"],"sub_categories":[],"readme":"# yolov4-deepsort\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1zmeSTP3J5zu2d5fHgsQC06DyYEYJFXq1?usp=sharing)\n\nObject tracking implemented with YOLOv4, DeepSort, and TensorFlow. YOLOv4 is a state of the art algorithm that uses deep convolutional neural networks to perform object detections. We can take the output of YOLOv4 feed these object detections into Deep SORT (Simple Online and Realtime Tracking with a Deep Association Metric) in order to create a highly accurate object tracker.\n\n## Demo of Object Tracker on Persons\n\u003cp align=\"center\"\u003e\u003cimg src=\"data/helpers/demo.gif\"\\\u003e\u003c/p\u003e\n\n## Demo of Object Tracker on Cars\n\u003cp align=\"center\"\u003e\u003cimg src=\"data/helpers/cars.gif\"\\\u003e\u003c/p\u003e\n\n## Getting Started\nTo get started, install the proper dependencies either via Anaconda or Pip. I recommend Anaconda route for people using a GPU as it configures CUDA toolkit version for you.\n\n### Conda (Recommended)\n\n```bash\n# Tensorflow CPU\nconda env create -f conda-cpu.yml\nconda activate yolov4-cpu\n\n# Tensorflow GPU\nconda env create -f conda-gpu.yml\nconda activate yolov4-gpu\n```\n\n### Pip\n(TensorFlow 2 packages require a pip version \u003e19.0.)\n```bash\n# TensorFlow CPU\npip install -r requirements.txt\n\n# TensorFlow GPU\npip install -r requirements-gpu.txt\n```\n### Nvidia Driver (For GPU, if you are not using Conda Environment and haven't set up CUDA yet)\nMake sure to use CUDA Toolkit version 10.1 as it is the proper version for the TensorFlow version used in this repository.\nhttps://developer.nvidia.com/cuda-10.1-download-archive-update2\n\n## Downloading Official YOLOv4 Pre-trained Weights\nOur object tracker uses YOLOv4 to make the object detections, which deep sort then uses to track. There exists an official pre-trained YOLOv4 object detector model that is able to detect 80 classes. For easy demo purposes we will use the pre-trained weights for our tracker.\nDownload pre-trained yolov4.weights file: https://drive.google.com/open?id=1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT\n\nCopy and paste yolov4.weights from your downloads folder into the 'data' folder of this repository.\n\nIf you want to use yolov4-tiny.weights, a smaller model that is faster at running detections but less accurate, download file here: https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.weights\n\n## Running the Tracker with YOLOv4\nTo implement the object tracking using YOLOv4, first we convert the .weights into the corresponding TensorFlow model which will be saved to a checkpoints folder. Then all we need to do is run the object_tracker.py script to run our object tracker with YOLOv4, DeepSort and TensorFlow.\n```bash\n# Convert darknet weights to tensorflow model\npython save_model.py --model yolov4 \n\n# Run yolov4 deep sort object tracker on video\npython object_tracker.py --video ./data/video/test.mp4 --output ./outputs/demo.avi --model yolov4\n\n# Run yolov4 deep sort object tracker on webcam (set video flag to 0)\npython object_tracker.py --video 0 --output ./outputs/webcam.avi --model yolov4\n```\nThe output flag allows you to save the resulting video of the object tracker running so that you can view it again later. Video will be saved to the path that you set. (outputs folder is where it will be if you run the above command!)\n\nIf you want to run yolov3 set the model flag to ``--model yolov3``, upload the yolov3.weights to the 'data' folder and adjust the weights flag in above commands. (see all the available command line flags and descriptions of them in a below section)\n\n## Running the Tracker with YOLOv4-Tiny\nThe following commands will allow you to run yolov4-tiny model. Yolov4-tiny allows you to obtain a higher speed (FPS) for the tracker at a slight cost to accuracy. Make sure that you have downloaded the tiny weights file and added it to the 'data' folder in order for commands to work!\n```\n# save yolov4-tiny model\npython save_model.py --weights ./data/yolov4-tiny.weights --output ./checkpoints/yolov4-tiny-416 --model yolov4 --tiny\n\n# Run yolov4-tiny object tracker\npython object_tracker.py --weights ./checkpoints/yolov4-tiny-416 --model yolov4 --video ./data/video/test.mp4 --output ./outputs/tiny.avi --tiny\n```\n\n## Resulting Video\nAs mentioned above, the resulting video will save to wherever you set the ``--output`` command line flag path to. I always set it to save to the 'outputs' folder. You can also change the type of video saved by adjusting the ``--output_format`` flag, by default it is set to AVI codec which is XVID.\n\nExample video showing tracking of all coco dataset classes:\n\u003cp align=\"center\"\u003e\u003cimg src=\"data/helpers/all_classes.gif\"\\\u003e\u003c/p\u003e\n\n## Filter Classes that are Tracked by Object Tracker\nBy default the code is setup to track all 80 or so classes from the coco dataset, which is what the pre-trained YOLOv4 model is trained on. However, you can easily adjust a few lines of code in order to track any 1 or combination of the 80 classes. It is super easy to filter only the ``person`` class or only the ``car`` class which are most common.\n\nTo filter a custom selection of classes all you need to do is comment out line 159 and uncomment out line 162 of [object_tracker.py](https://github.com/theAIGuysCode/yolov4-deepsort/blob/master/object_tracker.py) Within the list ``allowed_classes`` just add whichever classes you want the tracker to track. The classes can be any of the 80 that the model is trained on, see which classes you can track in the file [data/classes/coco.names](https://github.com/theAIGuysCode/yolov4-deepsort/blob/master/data/classes/coco.names)\n\nThis example would allow the classes for person and car to be tracked.\n\u003cp align=\"center\"\u003e\u003cimg src=\"data/helpers/filter_classes.PNG\"\\\u003e\u003c/p\u003e\n\n### Demo of Object Tracker set to only track the class 'person'\n\u003cp align=\"center\"\u003e\u003cimg src=\"data/helpers/demo.gif\"\\\u003e\u003c/p\u003e\n\n### Demo of Object Tracker set to only track the class 'car'\n\u003cp align=\"center\"\u003e\u003cimg src=\"data/helpers/cars.gif\"\\\u003e\u003c/p\u003e\n\n## Command Line Args Reference\n\n```bash\nsave_model.py:\n  --weights: path to weights file\n    (default: './data/yolov4.weights')\n  --output: path to output\n    (default: './checkpoints/yolov4-416')\n  --[no]tiny: yolov4 or yolov4-tiny\n    (default: 'False')\n  --input_size: define input size of export model\n    (default: 416)\n  --framework: what framework to use (tf, trt, tflite)\n    (default: tf)\n  --model: yolov3 or yolov4\n    (default: yolov4)\n    \n object_tracker.py:\n  --video: path to input video (use 0 for webcam)\n    (default: './data/video/test.mp4')\n  --output: path to output video (remember to set right codec for given format. e.g. XVID for .avi)\n    (default: None)\n  --output_format: codec used in VideoWriter when saving video to file\n    (default: 'XVID)\n  --[no]tiny: yolov4 or yolov4-tiny\n    (default: 'false')\n  --weights: path to weights file\n    (default: './checkpoints/yolov4-416')\n  --framework: what framework to use (tf, trt, tflite)\n    (default: tf)\n  --model: yolov3 or yolov4\n    (default: yolov4)\n  --size: resize images to\n    (default: 416)\n  --iou: iou threshold\n    (default: 0.45)\n  --score: confidence threshold\n    (default: 0.50)\n  --dont_show: dont show video output\n    (default: False)\n  --info: print detailed info about tracked objects\n    (default: False)\n```\n\n### References  \n\n   Huge shoutout goes to hunglc007 and nwojke for creating the backbones of this repository:\n  * [tensorflow-yolov4-tflite](https://github.com/hunglc007/tensorflow-yolov4-tflite)\n  * [Deep SORT Repository](https://github.com/nwojke/deep_sort)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FtheAIGuysCode%2Fyolov4-deepsort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FtheAIGuysCode%2Fyolov4-deepsort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FtheAIGuysCode%2Fyolov4-deepsort/lists"}