YOLOv5 compared to Faster RCNN. Who wins?
By: Priya Dwivedi
Tags: Deep Learning, Computer Vision, Object Detection, Artificial Intelligence, Data Science

YOLOv5 compared to Faster RCNN. Who wins?

Doing cool things with data!

Introduction

The deep learning community is abuzz with YOLO v5. This blog recently introduced YOLOv5 as — State-of-the-Art Object Detection at 140 FPS. This immediately generated significant discussions across Hacker News, Reddit and even Github but not for its inference speed. Two prominent issues were — Should the model be called YOLO and are the speed benchmarking results accurate and reproducible. If you are interested in Roboflow’s response then you can find it here.

All the controversy aside, YOLOv5 looked like a promising model. So I have compared it to one of the best two stage detectors — Faster RCNN. To do this comparison, I have taken 3 videos from with different contexts and run the 2 models side by side. My assessment includes observations on the quality of results and inference speed. So lets get started!

YOLOv5 model

The YOLOv5 implementation has been done in Pytorch in contrast with the previous developments that used the DarkNet framework. This makes it easier to understand, train with it and deploy this model. There is no paper released with YOLO-v5. My understanding is that architecturally it is quite similar to YOLO-v4. One different may be the use of Cross Stage Partial Network (CSP) to reduce computation cost. It is still not clear if YOLO-v5 runs faster than YOLO-v4 but I prefer Pytorch implementations and I am amazed with how easy it is to train with this model. My personal experience of running inference through it was also seamless.

The release of YOLOv5 includes five different models sizes: YOLOv5s (smallest), YOLOv5m, YOLOv5l, YOLOv5x (largest). The inference speed and mean average precision (mAP) for these models is shared below:

YOLO v5 stats from UltraLytics repo

Inference using YOLO-v5

The first step would be to clone the repo for YOLO-v5. Install all the requirments. I use Pytorch 1.5 and the code works without any problems.

You can download all the weights for different pretrained COCO models using:

bash weights/download_weights.sh

To run inference on a video, you have to pass the path to the video and the weights of the model you want to use. If the weights argument is not set, then by default code runs on the YOLO small model. Sample arguments I used are shared below:

python detect.py --source video/MOT20-01-raw-cut1.mp4 --output video_out/ --weights weights/yolov5s.pt --conf-thres 0.4

The output video will be saved in the output folder

Training using YOLO-v5

I haven’t personally tried training using YOLO-v5 on a custom data set but a good step by step tutorial is shared by Roboflow on Youtube here.

Faster RCNN Model

For the Faster RCNN model, I used the pretrained model from Tensorflow Object Detection. Tensorflow Object Detection shares COCO pretrained Faster RCNN for various backbones. For this blog I have used the Fatser RCNN ResNet 50 backbone. This repo has shared a nice tutorial on how to do inference using their pretrained model here.

Comparison of YOLOv5 model with Faster RCNN

The first scene I chose was a street driving scene considering the importance to self driving car industry. The results from both these models is shared below:

YOLOv5 model evaluated on Driving Video

Faster RCNN evaluated on Driving Video

YOLO model seems much better at detecting smaller objects — traffic lights in this case and also is able to pick up the car when it is farther away i.e smaller.

Run Speed of YOLO v5 small(end to end including reading video, running model and saving results to file) — 52.8 FPS!

Run Speed of Faster RCNN ResNet 50(end to end including reading video, running model and saving results to file) —21.7 FPS

These results are evaluated on NVIDIA 1080 Ti.

So far YOLO v5 seems better than Faster RCNN

YOLO v5 and Faster RCNN comparison 1

The next video is a basketball match video from youtube. The results of both models are shared below:

YOLO v5 on Basketball Video

Faster RCNN ResNet 50 on Basketball Video

The Faster RCNN model is run at a threshold of 60% and one could argue it is picking up the crowd with a single person label but I prefer YOLO here for the cleanliness of results. Both models have false positive on the abc logo.

I was also disappointed on how both failed to detect the basketball ball even though sports ball is a category in COCO. Their tally is now:

YOLO v5 and Faster RCNN comparison 2

For the final video, I chose an indoor crowded scene from MOT data set. This is a challenging video with low lighting, distant and dense crowds. The results from both the models are shown below.

YOLO v5 model tested on indoor crowded scene from MOT data set

Faster RCNN model tested on indoor crowded scene from MOT data set

This is interesting. I would say both these models struggle to detect people in the distance as they walk into the corridor. This could be attributed to low light and smaller objects. When the crowd gets closer to the camera, both are able to pick up overlapping people.

YOLO v5 and Faster RCNN comparison 2

Conclusion

The final comparison b/w the two models shows that YOLO v5 has a clear advantage in terms of run speed. The small YOLO v5 model runs about 2.5 times faster while managing better performance in detecting smaller objects. The results are also cleaner with little to no overlapping boxes. Ultralytics have done a fabulous job on their YOLO v5 open sourcing a model that is easy to train and run inference on.

This blog also shows an emerging trend with computer vision object detection towards moving to models that are both faster and accurate.

If you have tried YOLOv5 please share your experience in the comments below.

At Deep Learning Analytics, we are extremely passionate about using Machine Learning to solve real-world problems. We have helped many businesses deploy innovative AI-based solutions. Contact us through our website here if you see an opportunity to collaborate.

References