top of page
Mayuresh Madiwale

šŸŖ Kite Detection using YOLO šŸš€





YOLO V8 is the most recent advancement in YOLO models. I have tried using it for the purpose of Kite Detection. The main motive of this project is to find out if YOLO V8 is able to detect small objects or not. For the project, I have made a dataset of Kite Images. We will see the complete project here in detail.



YOLO V8


Initially released on 10th of January 2023 by Ultralytics, YOLO V8 is the the latest SOTA (State Of The Art) model which is capable of doing:

  1. Object Detection

  2. Image Classification

  3. Instance Segmentation

They have also added a new way to run the model in our system. All the previous models have to be run using GitHub Cloning, YOLO V8 however, can be run using new Ultralytics Library that they have now made. We can easily use this library in CLI (Command Line Interface) or by simply importing the library in our Jupyter/ Colab notebook.

To get more idea or to use it you can visit their official GitHub :- github.com/ultralytics


The Dataset šŸŖ

This is an "End to End" project so I have made the dataset from scratch. Firstly I have downloaded few images from internet and then some images I have shot on my phone. I have also recorded a few videos of kites flying and then used the videos as well.

For annotation of these images, I have used Roboflow as it is a very easy to use free tool for annotation as well as Image Augmentation. We will see step by step process that I have followed.


STEP 1.


visit www.roboflow.com and login using your google account or any account of our choice.


STEP 2.


Follow the steps given to set up your workspace.



Create a public workspace.



STEP 3.


Create your new project.



Fill up the required details as given in the form.



STEP 4.


Add the images for annotation.



You will have to assign the images to yours's or your group member's mail id.



STEP 5.


Annotation is very easy in this case as Roboflow has a Smart Polygon feature which detects the object of interest and adds a polygon around it.



Have a look at the following to see the process.




STEP 6.


Add the annotated images to the dataset.



STEP 7.


Train - Test Split of the dataset. You can customize it as per your need.


STEP 8.


Image augmentation is where you add more images to the data by using augmentation steps such as rotation, flip, gray-scaling, cropping, shearing, etc. This will inflate the data and make it robust and healthy.



STEP 9.


Export the dataset to your required format. I have chosen YOLO V8 here. And use the dataset for training.




Training šŸš†

For training the model, I have used Google Colab as it comes with free GPU's to train faster.


Installing The Ultralytics Library

This step is pretty much same as we do for any python library. The script is as follows:


pip install ultralytics

To do the same in Colab, we have to simply put an exclamation mark before pip.


Import the Library and run checks

Import the library and look if everything is correct or not.


import ultralytics
ultralytics.checks()

Output will be something like this:-


Ultralytics YOLOv8.0.5 šŸš€ Python-3.8.16 torch-1.13.0+cu116 CUDA:0 (Tesla T4, 15110MiB)
Setup complete āœ… (2 CPUs, 12.7 GB RAM, 23.0/78.2 GB disk)

Import the custom Dataset

Roboflow is not a default library in colab so we will have to install it and then import the dataset in our disk.


!pip install roboflow 

from roboflow import Roboflow

rf = Roboflow(api_key="API_KEY_TO_DATASET_FROM_ROBOFLOW")
project = rf.workspace("MY-WORKSPACE").project("kite-detector")
dataset = project.version(5).download("yolov8")

Run scripts to load model and training on dataset

Give the required commands for training. You just have to give the path to the data.yaml file to the data argument.


from ultralytics import YOLO  

# Load a model 
model = YOLO('yolov8s.pt')  # load a pretrained model (recommended for training)


# Use the model 
results = model.train(data='/content/kite-detector-5/data.yaml'

This will take some time for training. we can see the process in the output. After training is complete, we get the best and last model in form of PyTorch models (.pt format).


Testing on Test Images

Here, I have use CLI method to test the model on test images.


!yolo task = detect mode=predict model="/PATH TO/best.pt" conf=0.25 source='/content/kite-detector-5/test/images/'

After prediction, the images will be saved to runs/detect/predict


Here is one of the results of images: -


For Inferencing on Video, we have to specify the source to the path of your video.



YOLO V5


Yolo v5 is also a great model made by Ultralytics in 2020. Earlier it was just a Object detection model but in August 2022, they have added Image segmentation and Image classification.

To use this model, we will have to clone their GitHub repo and work with it.

To get complete information go through this link: Yolov5 GitHub


Clone YOLOV5 from GitHub.

Run following command to clone.


!git clone https://github.com/ultralytics/yolov5

Train the model

Run the code to train the model on our dataset


%cd /content/drive/MyDrive/yolov5with_video
!python train.py --img 320 --batch 64 --epochs 300 --data dataset.yaml --weights yolov5s.pt --cache --patience 50

After training is complete, we will again have best.pt and last.pt in runs/train/exp


Detection/Inferencing on test images and videos

Again we can run the code as follows to get inference on out test dataset


!python detect.py --weights /PATH_TO/best.pt --img 320 --conf 0.25 --source /PATH_TO/video.mp4 --line-thickness 1 

Export the model to TFlite so to make a Android App

Yolo V8 is not available to export to tflite as of today (29.01.23). Thus I have made an Android app using Yolo V5. To export .pt to .tflite, use following code:


!python export.py --weights /PATH_TO/best.pt --include tflite  --img 320

The Output will be as follows.


TensorFlow Lite: export success āœ… 50.4s, 
saved as /PATH_WHERE_.PT_IS_SAVED/best-fp16.tflite (13.5 MB)  

Export complete (61.5s) 

Results saved to /content/Yolov5/runs/train/exp/weights

To make the Android app, there are plenty of tutorials on YouTube/ GitHub to follow from or just take help from any Android Developer friend šŸ˜…

Here is the output of the android app that I have:



YOLO V5 vs YOLO V8

Here is a small comparison between YOLO V5 and YOLO V8 on same video. We can see that YOLO V8 is better than V5.



. . .

GitHub Link: - Here


Like , Share if you found this helpful.


I am open to any Suggestions/ Corrections/ Comments so please feel free.


Also , Connect with me on LinkedIn


Open to Entry Level Jobs as Data Scientist/Data Analyst. Please DM on LinkedIn for my Resume for any openings in near future šŸ¤— šŸ™

168 views0 comments

Recent Posts

See All

Comments


bottom of page