So I have just recently started exploring machine learning, and for a project I was required to train the YOLO v5 model. I first tried it on the coco128 dataset:https://www.kaggle.com/ultralytics/coco128..

repository of the yolo v5: https://github.com/ultralytics/yolov5

I followed this tutorial: https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data step by step and managed to train the model succesfully, it is detecting objects as I intended it to do.

I wanted to have a very basic overview an what is basically happening when we are "training" the model.

The command used for training was:

python train.py --img 640 --batch 16 --epochs 5 --data coco128.yaml --weights yolov5s.pt

From what I understand, this tells the command line to run the file "train.py" (which uses argeparse library) with the following arguments: 640 (image size), 16 (batch size for batch gradient descent), 5 (no. of epochs), coco128.yaml (the config file), and yolov5s.pt (the weights file).


  • The tutorial mentions that the weights are pretrained. This is confusing me because I thought the entire objective of "training" a model is to find the correct weights for the parameters. If the weights are already supplied, what exactly is the training achieving? It has been fed a bunch of images along with the labels for the bounding boxes for that images. What does it do with these images and labels to become capable of predicting objects?
  • The coco128.yaml mentions a path for the "validation" folder. What exactly is a "validation" folder used for?
  • $\begingroup$ when you say image size, does 640 mean 640 pixels X 640 pixels? Or 640 images? $\endgroup$ Commented Jun 7, 2021 at 11:39

1 Answer 1


About Pre-trained model : This is a very common practise (especially in image recognition) and here is how we use it.

Let's imagine you want to recognize different types of food (beef, pork, vegetables, ...). You know some networks already exist that recognize all types of objects (boats, cars, food, sofas, ...). This objective of transfer learning is to use these models and adapt it to your task, so you pick an already trained model, and train it again, but only with your data (in our example types of food). Being able to recognize and distingish different objects is not useless for your task, so even if your network doesn't do the the same thing as the initial model, what the initial model has learned is used as foundations to learn your task.

We call this fine-tuning the model, it is basically using a complicated network that would be way too heavy to train because the dataset is not big enough, and just adjusting it so it performs our specialized task.

In your tutorial, the dataset Coco128 is made of 128 images, which is not enough for the training of a model as big as YOLOv5. So you use the pretrained weights and fine-tune it with your dataset. As far I as understand, the objective of the tutorial is to see how the model overfits these 128 images.

About validation, we usually splits datasets into 3 parts :

  1. Training set : used to train the models. (~80% dataset)
  2. Testing set : used to test the trained models, this part is the one used to estimate the accuracy of the model. (~15% dataset)
  3. Validation set : used at the very end, to validate the fact that our model works correctly. (~5% dataset)

In many cases, Testing and validation datasets are the same (because validation dataset often is not necessary).

In your tutorial, what they call validation set is what I usually call the testing dataset, and it is the same as the training set, so bascially all your sets are the same. (it is very very very uncommon to do so, but since the goal of the tutorial is to see how we overfit this set, it makes sense here).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.