In this project, I used YOLO algorithm trained on COCO dataset for object detection task. I used pretrained Yolov2 model which can downloaded from the official YOLO website.
Examples
Recommended System Requirements to run model.
- A good CPU and a GPU with atleast 4GB memory
- Atleast 8GB of RAM
- Active internet connection to download YOLOv2 weights and cfg file.
Required Libraries for Python along with their version numbers used while making & testing of this project
- Python - 3.6.7
- Numpy - 1.16.4
- Tensorflow - 1.13.1
- Keras - 2.2.4
- PIL - 4.3.0
- Total params: 50,983,561
- Trainable params: 50,962,889
- Non-trainable params: 20,672
Just follow 6 simple steps :
- Clone repository to preserve directory structure
git clone https://github.com/dabasajay/YOLO-Object-Detection.git
- Download Darknet model cfg and weights from the official YOLO website and put them in
model_data/
folder.
Direct terminal commands
wget https://pjreddie.com/media/files/yolov2.weights
mv yolov2.weights "model_data/yolov2.weights"
wget https://github.com/pjreddie/darknet/raw/master/cfg/yolov2.cfg
mv yolov2.cfg "model_data/yolov2.cfg"
- Review
config.py
for paths and other configurations (explained below) - Run
yad2k.py
to convert YOLOv2 model from darknet to keras model which will be saved inmodel_data/
folder. - Put all your images you want to test in
images/
directory.
Note: All images are resized to 608x608 to feed into YOLOv2 model - Run
YOLO.py
and MAGIC! Output images will be saved inoutput/
directory
If you face any problem converting keras model or anything: email me at [email protected]
Acknowledgement: Script yad2k.py
for conversion of darknet to keras model is taken from Allan Zelener - YAD2K: Yet Another Darknet 2 Keras github repo and modified a little bit.
keras_model_path
:- File path of keras converted yolov2 model in .hdf5 formatmodel_weights
:- File path of yolov2 weights file from darknet (Downloaded file)model_cfg
:- File path of yolov2 configuration file from darknet (Downloaded file)anchors_path
:- File path of yolo_anchors.txtclasses_path
:- File path of coco_classes.txttest_path
:- Folder path containing images for testing modeloutput_path
:- Folder path containing output of images from test_pathscore_threshold
:- Score(Confidence of predicted class) threshold. Lower value leads to more class predictions but less confident about predictions, higher leads to less class predictions but more confident about predictions.iou_threshold
:- Intersection over union threshold.random_seed
:- Random seed for reproducibility of resultsfont_path
:- File path of font to write on bounding boxes in image
The ideas presented in this repo came primarily from the two YOLO papers. The implementation here also took significant inspiration and used many components from Allan Zelener's github repository. The pretrained weights used in this project came from the official YOLO website.
- Joseph Redmon, Santosh Divvala, Ross Girshick, Ali Farhadi - You Only Look Once: Unified, Real-Time Object Detection (2015)
- Joseph Redmon, Ali Farhadi - YOLO9000: Better, Faster, Stronger (2016)
- Allan Zelener - YAD2K: Yet Another Darknet 2 Keras
- The official YOLO website