[Yolov7] train the newest Yolo with your custom data

Murat A. Avcu
3 min readAug 14, 2022

--

In this Medium story, I’m gonna show you How to train the newest Yolov7 with the custom data. First things first we need a dataset.

Data Preparation Section

I have planned to detect some sheep and count them in a video, so I need some sheep photos. You can easily find data whatever you want on Kaggle or such platforms. I’ve created a dataset that contains 201 sheep images. In order to feed our model with data, we need first to get annotated this raw image data. I have selected roboflow.com. This is how it looks for my data project :

Then, I labeled all images by hand. It sounds exhausting but this is true :D

I had to choose from each of the images the area which contains sheep. After all this process we are good to deploy our data project to use in Yolo. You can select the deploy tab on the roboflow project page then you have got various versions like Yolov7 Pytorch, Yolov5 Pytorch, Yolov4 Keras so on. We are choosing Yolov7 Pytorch.

After that we have got this:

We are copying this snippet to use after in our Yolo code.

Code Section

Now we are creating our Google colab notebook to profit from free GPUs.As the first step in the coding section, let’s download the yolov7

then let’s use the snippet that we are in the data preparation section got

The desired moment! We are good to go. Let’s train the Yolo with custom hyperparameters

Training time depends on your GPU I am using colab pro. Pro provides me tesla p100 and it takes around 20 minutes to complete.

See the beautiful results

To see our results:

The above line will detect sheep on our test dataset.

With these lines, you can easily see how good your model predicted. At the end, I want to share the video in which I applied my Yolo model to detect and count some sheep :D

My Linkedin, My Github

--

--