|
| 1 | +# YOLO-Object-Counting-API |
| 2 | +Real time Object Counting api. Implemented with the [YOLO](https://arxiv.org/pdf/1612.08242.pdf) algorithm and with the [SORT](https://arxiv.org/pdf/1703.07402.pdf) algorithm |
| 3 | + |
| 4 | +The implementation is using model in same format as darkflow and darknet. Weight files, as well as cfg files can be found [here](http://pjreddie.com/darknet/yolo/). Darklow supports only YOLOv1 and YOLOv2. Support for YOLOv3 has not yet been implemented. |
| 5 | + |
| 6 | +In order to achieve the best performance, you should have Cuda and tensorflow-gpu installed on Your device. |
| 7 | + |
| 8 | +## Demo |
| 9 | +### Count objects of a specified class crossing a virtual line |
| 10 | + |
| 11 | +#### Graduate pedestrian |
| 12 | + |
| 13 | +[](https://www.youtube.com/watch?v=CF_UPJvWr-s&ab_channel=NatthasathSaksupanara) |
| 14 | + |
| 15 | +#### Counting pedestrains |
| 16 | + |
| 17 | +<p align="center"> <img src="inputs/pedestrians_output.gif"/> </p> |
| 18 | + |
| 19 | +#### Highway traffic counting |
| 20 | + |
| 21 | +<p align="center"> <img src="inputs/highway_traffic_output.gif"/> </p> |
| 22 | + |
| 23 | +### Count objects on a video |
| 24 | + |
| 25 | +<p align="center"> <img src="inputs/count_objects_on_video.gif"/> </p> |
| 26 | + |
| 27 | +### Count objects on a single frame |
| 28 | + |
| 29 | +<p align="center"> <img src="inputs/count_people_output.jpg"/> </p> |
| 30 | + |
| 31 | + |
| 32 | +# Set up |
| 33 | +## Dependencies |
| 34 | + |
| 35 | +``` |
| 36 | +-tensorflow 1.0 |
| 37 | +-numpy |
| 38 | +-opencv 3 |
| 39 | +``` |
| 40 | + |
| 41 | +## Getting started |
| 42 | + |
| 43 | +You can choose _one_ of the following three ways to get started with darkflow. |
| 44 | + |
| 45 | +1. Just build the Cython extensions in place. NOTE: If installing this way you will have to use `./flow` in the cloned darkflow directory instead of `flow` as darkflow is not installed globally. |
| 46 | + ``` |
| 47 | + python3 setup.py build_ext --inplace |
| 48 | + ``` |
| 49 | +
|
| 50 | +2. Let pip install darkflow globally in dev mode (still globally accessible, but changes to the code immediately take effect) |
| 51 | + ``` |
| 52 | + pip3 install -e . |
| 53 | + ``` |
| 54 | +
|
| 55 | +3. Install with pip globally |
| 56 | + ``` |
| 57 | + pip3 install . |
| 58 | + ``` |
| 59 | +
|
| 60 | +## Required files |
| 61 | +
|
| 62 | +The YOLO algoritym impementation used in this project requires 3 files. Configuration of network (.cfg), trained weights (.weights) and labels.txt. |
| 63 | +
|
| 64 | +YOLO implementation used in this project enables usage of YOLOv1 and YOLOv2, and its tiny versions. Support for YOLOv3 has not yet been implemented. |
| 65 | +
|
| 66 | +
|
| 67 | +### .cfg files |
| 68 | +Configuration file determines a network architecture. Configurations can be found [here](http://pjreddie.com/darknet/yolo/). In example scripts we assume that the configuration is placed in cfg/ folder. Location of used .cfg file is specyfied in the options object used in the code. |
| 69 | +
|
| 70 | +The .cfg file can be downloaded using the following command: |
| 71 | +```bash |
| 72 | +wget https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov2.cfg -O cfg/yolov2.cfg |
| 73 | +``` |
| 74 | +### .weights files |
| 75 | +The .weights files contain trained parameters of a network. In example scripts we assume the weights are placed in bin/ folder. Location of used .weights file is specyfied in the options object used in the code. |
| 76 | + |
| 77 | +The .weights file can be downloaded using the following command: |
| 78 | +```bash |
| 79 | +wget https://pjreddie.com/media/files/yolov2.weights -O bin/yolov2.weights |
| 80 | +``` |
| 81 | +### labels.txt files |
| 82 | + |
| 83 | +This file is list of classes detected by a YOLO netowork. It shoud contain as many classes as it is specyfied in a .cfg file. |
| 84 | + |
| 85 | +## Run counting |
| 86 | + |
| 87 | +Once You have all dependencies instaled and all required files You can start counting objects. Object counting is carried out by an ObjectCuntingAPI object. |
| 88 | + |
| 89 | +Examples of counting below |
| 90 | + |
| 91 | +### Count cars on crosing a virtual line |
| 92 | +```bash |
| 93 | +python3 count_cars_crosing_virtual_line.py |
| 94 | +``` |
| 95 | + |
| 96 | +### Count objects on video from Video Camera |
| 97 | +```bash |
| 98 | +python3 count_objects_from_camera.py |
| 99 | +``` |
| 100 | + |
| 101 | +### Count people on image |
| 102 | +```bash |
| 103 | +python3 count_people_on_image.py |
| 104 | +``` |
| 105 | + |
| 106 | +## Credits |
| 107 | +The following open source projects were used in the implementation |
| 108 | + |
| 109 | +### Darkflow |
| 110 | + |
| 111 | +The YOLO algorithm impementation - [Darkflow](https://github.com/thtrieu/darkflow) |
| 112 | + |
| 113 | +### Python Traffic Counter |
| 114 | + |
| 115 | +[Object counting with YOLO and SORT](https://github.com/bharath5673/python-traffic-counter-with-yolo-and-sort). Similar project, but instead of using the darklow YOLO implementation, it uses the opencv YOLO implementation, so there is no GPU acceleration. |
| 116 | + |
| 117 | +### Deep Sort |
| 118 | +Object tracking and counting - [SORT](https://github.com/abewley/sort) |
| 119 | + |
| 120 | +## Images and Videos sources |
| 121 | +Highway surveillance [video](https://www.youtube.com/watch?v=PJ5xXXcfuTc) |
| 122 | + |
| 123 | +Pedestrian surveillance [video](https://www.youtube.com/watch?v=aUdKzb4LGJI) |
| 124 | + |
| 125 | +## Authors |
| 126 | +* [tugot17](https://github.com/tugot17) |
| 127 | + |
| 128 | +## License |
| 129 | + |
| 130 | +This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details |
| 131 | + |
| 132 | + |
| 133 | +That's all. |
0 commit comments