This is a project I made to detect owls and sheep using Yolov8 and OpenImages v7 database.
I dowloaded the dataset using OIDv4 ToolKit, which dowloads the latest OpenImages dataset. To do so, first I had to clone the OIDv4 ToolKit github repository using the following command:
git clone https://github.com/EscVM/OIDv4_ToolKit.git
After that, I downloaded all the requirements using the following command:
pip install -r requirements.txt
Finally for the dataset download, I downloaded it using the following commands:
python main.py downloader --classes Owl --type_csv All
python main.py downloader --classes Sheep --type_csv All
Each command downloaded one class. --type_csv All
argument ensures that we download train, validation and test splits.
Next, I uploaded the downloaded images and the accompanying .txt
files to Roboflow to convert the downloaded .txt
files to Yolov8 format.
After the annotations were converted to Yolov8 format, I exported the dataset using Roboflow's download link:
For training, I used Google Colab because it offers free GPUs to use and they are better than the one I have locally. The code used can be found in the yolov8_oiv7.ipynb file.
In short, I first had to install some required packages, such as the ultralytics and roboflow packages. Then I had to load the dataset prepared on Roboflow using the block of code seen above. After that, I had to edit the data.yaml file so that the paths leading to the data were correct. Next, I downloaded the pre-trained yolov8n-oiv7.pt
model. Finally, I trained the model using the downloaded model and dataset.
Results:
The training lasted a little less than an hour.
The testing of the model is done using the following command:
!yolo detect predict model=/path/to/model.pt source='/path/to/image'
specifically in my case:
!yolo detect predict model=/content/drive/MyDrive/best_colab_50e.pt source='/content/owl-sheep-1/test/images/2bc6fded1a1ff77f_jpg.rf.d895bdb06e28cdc155bb22daac1b635f.jpg'
The model was tested on several images, here are a couple of examples:
This approach is largely the same, the only difference is that the dataset prepared on Roboflow was downloaded locally as a .zip
file.
After unzipping the files, I downloaded the pre-trained yolov8n-oiv7.pt model, however, I trained the model via the command line using the following command:
yolo detect train data=data.yaml model=yolov8-oiv7.pt epochs=10 imgsz=640
I trained it only for 10 epochs as the training was too strenuous on my GPU.
Results:
The training lasted about two hours.
Testing the local model was done using the same command, but with adjusted paths.
Here are a couple of results:
In this approach I downloaded the dataset using the dataset_download.py script and I downloaded only Owl and Sheep classes. Along with the images came the detections.csv
file which contained relevant information about detections in the images, however, it was not in the Yolov8 format. I also had to download the fiftyone package to execute this script.
This format of dataset was not in the Yolov8 format so I had to format it to fit.
First, I executed the csv_eliminate.py script which eliminated any rows in the detections.csv
file which detected non owl or sheep objects as they were not needed.
Next, I used the csv_to_txt.py script to convert the relevant data in the detections.csv
file into .txt
files in the Yolov8 format.
After converting the given files into the Yolov8 format, I was ready to begin training. The script used can be found in the yolov8_train.ipynb file. But in essence, the training process was the same as it was in Approach 1.
This model was also only trained on 10 epochs because it was done locally.
Results:
The training lasted about 1:45 hours.
Again, the testing is the same. Here are a couple of examples:
Overall, the best results came from the model trained on Google Colab for 50 epochs, which should come to no surprise as it was trained 5 times as long as the local models. Additionaly, it took much shorter to train the model on Google Colab.
However, it should be noted that although worse, the results of the local models were not bad. They were not perfect, but they yielded acceptable results for only 10 epochs.