Testing YOLO v3 CS:GO Keras object detection

Posted August 28, 2019 by Rokas Balsys



Running the aim bot:

Welcome to another YOLO v3 custom object detection tutorial. In this part I will give you all the details how I trained model to detect CS:GO enemies. Trained model I used to write a custom aim bot script. First if you want to test it by yourself you can find code on my GitHub. Alternatively, just clone whole directory with:

git clone https://github.com/pythonlessons/YOLOv3-object-detection-tutorial.git

This repository has 2 folders YOLOv3-CSGO-detection and YOLOv3-custom-training, this tutorial is about first directory. So move to it.

First thing you should do is go to logs folder and unzip trained_weights_final.7z to trained_weights_final.h5 to same location. This is our trained YOLO v3 detection model.

Now run realtime_detect.py script and make sure that your model_path, anchors_path and classes_path are in right location. Install all necessary libraries if you don't have few of them.

Note that you must run realtime_detect.py as administrator, the same way I was doing in video tutorial. Otherwise moving target and shooting will not work. You should open CMD as administrator, locate to YOLOv3-CSGO-detection folder and run python realtime_detect.py

Aim bot performance:

First of all, I was inspired to do this tutorial because I was not satisfied with results from my past tutorial, where I couldn't get stable FPS in aim bot. At that time, one of my solutions was to explore and train YOLO model, and finally I did that! So as a result, maximum I can get is 22-24 FPS when not recording above video tutorial:

FPS.jpg

I believe that there is many ways how to improve this aim bot, but I decided not to invest more time in this. So there is few issues to fix:
1. Need larger training database, because it sometimes detects wrong or do not detect heads at all.
2. Right now I wrote in code, that bot targets and shoots one time per detection. It means if I receive 20 FPS, it tries to move mouse to target 20 times per second, and if we are targeting at head, shoot it at same rate.
3. When we are detecting more than one object (heads in my example), bot constantly change targets. Would be nice to implement some kind of object tracking or checking if it's the same object.

If someone will improve my code, please, share it with me.

YOLO v3 aim bot training:

For training I used same dataset as last time. These images you can find on this GitHub link. To convert XML files in a right format to train YOLO model I wrote a script voc_to_YOLOv3_NO_CLASSES.py. This script doesn't require you to create classes file or something like that. At first loop it collects all classes used in XML files. And on second loop it creates 2 files which are used for training, these files are saved in model_data folder. Then just run train.py according to my previous tutorial, where I explained how to train custom YOLO v3 model.

I must mention that I wrote another cool script called collect_XLM_images.py. We can run this script uncommenting 2 lines in my realtime_detect.py code:

#if len(ObjectsList) > 0:
#    CreateXMLfile(img_clean, ObjectsList)

So this script creates an XML file, with object coordinates received in real time detection. This way we can much faster collect more training data, we just need to play around laggy CS:GO while running real time detection. After we collect these images, we need to check them all, in this way we can fix bad detection or detected rectangle size and so on. I just found that in this way it's much easier to generate more training data.

Conslusion:

This was my last tutorial with object detection while creating aim bot for CS:GO. Maybe in future I will do something similar, we'll see, time will show. But for now I will invest time to another areas.