Answers.Body: <p>I will try to answer you based on my previous experience with training YOLO architectures. Hopefully, this can help you build your object detection model.</p>
  <p>The first thing to note is your training data. The fact that the loss has decreased on the model is a very good sign that it is improving its accuracy. However, if the accuracy drops when using the test dataset, it means that the model did not generalize well for the task given. This is usually a case of overfitting.</p>
  <p>The size of your dataset is an important consideration. In general, 160 data points are too few for training an object detection module. Therefore, the first thing I would recommend is to increase the size of your dataset. If increasing the dataset is not possible, you may want to consider other types of models. You could try using a lighter version of YOLO, such as YOLO-tiny, which is a less computationally expensive model with fewer weights to train. This means that it will learn to do the task faster.</p>
  <p>Another thing you can consider is using techniques like transfer learning or employing pre-trained models. Usually, YOLO's open-source repositories have pre-trained weights that are trained with ImageNet or the COCO dataset. I did not see any in your shared repository, but it is highly recommended to use them as a general rule.</p>
  <p>Finally, since you are training an object detection module, you should consider the type of background in which you are searching for the image. It is not the same to train object detection for a camera with real-world imagery as it is to train an object detection module for a user interface. In any case, it is a good strategy to augment the data to provide more diversity to the neural network. For this, you can try tools like <a href="https://albumentations.ai/" rel="nofollow noreferrer">Albumentations</a>. This tool will help augment the number of data points in a synthetic way, for example, through rotations, scaling, and changing colors. A trick that I have used is to embed the object I want to identify in different types of backgrounds, and in my use case, it has helped increase accuracy.
  I hope this helps!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-24T23:06:35.620Z
Answers.LastActivityDate: 2023-08-24T23:06:35.620Z
Answers.UserDisplayName: Cesar Ruiz
Body: <p>I am currently trying to train my own YOLOv1 network, based on this repository:
  <a href="https://github.com/ivanwhaf/yolov1-pytorch" rel="nofollow noreferrer">https://github.com/ivanwhaf/yolov1-pytorch</a></p>
  <p>The images I want to train look like this:</p>
  <p><a href="https://i.sstatic.net/Aw6P1.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Aw6P1.jpg" alt="enter image description here" /></a></p>
  <p>Three classes I want to detect:</p>
  <ul>
  <li>Class 0: A meter (the &quot;clocks&quot; at the bottom)</li>
  <li>Class 1: The number display</li>
  <li>Class 2: Each individual digit</li>
  </ul>
  <p>I generated 160 training images and automatically generated the YOLO bounding boxes, for the image above they look like this:</p>
  <pre><code>0.21875 0.5833333333333334 0.25 0.3333333333333333 0
  0.5 0.5833333333333334 0.25 0.3333333333333333 0
  0.78125 0.5833333333333334 0.25 0.3333333333333333 0
  0.5 0.14583333333333334 0.9375 0.20833333333333334 1
  0.890625 0.14583333333333334 0.09375 0.15833333333333333 2
  0.765625 0.14583333333333334 0.09375 0.15833333333333333 2
  0.640625 0.14583333333333334 0.09375 0.15833333333333333 2
  0.515625 0.14583333333333334 0.09375 0.15833333333333333 2
  0.390625 0.14583333333333334 0.09375 0.15833333333333333 2
  0.265625 0.14583333333333334 0.09375 0.15833333333333333 2
  </code></pre>
  <p>After 40 epochs or so I end up with a Loss of around <code>1.8</code> (the network started at 200) but the bounding boxes are no where near where they should be:</p>
  <p><a href="https://i.sstatic.net/Rgy5H.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Rgy5H.jpg" alt="enter image description here" /></a></p>
  <p>Red is the prediction and green are the ground truth bounding boxes.</p>
  <p>Do you have an idea why that is? Did I do something wrong with labelling the bounding boxes of the training images?</p>
  
Tags: <convolutional-neural-networks><training><yolo>
Title: YOLOv1 doesn't work for custom dataset
UserDisplayName: binaryBigInt
ThreadText: # YOLOv1 doesn't work for custom dataset
  
  (Asked by: username_0 on 2023-08-18)
  
  I am currently trying to train my own YOLOv1 network, based on this repository:
  https://github.com/ivanwhaf/yolov1-pytorch
  The images I want to train look like this:
  
  Three classes I want to detect:
  
  Class 0: A meter (the "clocks" at the bottom)
  Class 1: The number display
  Class 2: Each individual digit
  
  I generated 160 training images and automatically generated the YOLO bounding boxes, for the image above they look like this:
  0.21875 0.5833333333333334 0.25 0.3333333333333333 0
  0.5 0.5833333333333334 0.25 0.3333333333333333 0
  0.78125 0.5833333333333334 0.25 0.3333333333333333 0
  0.5 0.14583333333333334 0.9375 0.20833333333333334 1
  0.890625 0.14583333333333334 0.09375 0.15833333333333333 2
  0.765625 0.14583333333333334 0.09375 0.15833333333333333 2
  0.640625 0.14583333333333334 0.09375 0.15833333333333333 2
  0.515625 0.14583333333333334 0.09375 0.15833333333333333 2
  0.390625 0.14583333333333334 0.09375 0.15833333333333333 2
  0.265625 0.14583333333333334 0.09375 0.15833333333333333 2
  
  After 40 epochs or so I end up with a Loss of around 1.8 (the network started at 200) but the bounding boxes are no where near where they should be:
  
  Red is the prediction and green are the ground truth bounding boxes.
  Do you have an idea why that is? Did I do something wrong with labelling the bounding boxes of the training images?
  
  **Tags:** convolutional-neural-networks, training, yolo
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-08-24. Score: 1
  
  I will try to answer you based on my previous experience with training YOLO architectures. Hopefully, this can help you build your object detection model.
  
  The first thing to note is your training data. The fact that the loss has decreased on the model is a very good sign that it is improving its accuracy. However, if the accuracy drops when using the test dataset, it means that the model did not generalize well for the task given. This is usually a case of overfitting.
  
  The size of your dataset is an important consideration. In general, 160 data points are too few for training an object detection module. Therefore, the first thing I would recommend is to increase the size of your dataset. If increasing the dataset is not possible, you may want to consider other types of models. You could try using a lighter version of YOLO, such as YOLO-tiny, which is a less computationally expensive model with fewer weights to train. This means that it will learn to do the task faster.
  
  Another thing you can consider is using techniques like transfer learning or employing pre-trained models. Usually, YOLO's open-source repositories have pre-trained weights that are trained with ImageNet or the COCO dataset. I did not see any in your shared repository, but it is highly recommended to use them as a general rule.
  
  Finally, since you are training an object detection module, you should consider the type of background in which you are searching for the image. It is not the same to train object detection for a camera with real-world imagery as it is to train an object detection module for a user interface. In any case, it is a good strategy to augment the data to provide more diversity to the neural network. For this, you can try tools like [Albumentations](https://albumentations.ai/). This tool will help augment the number of data points in a synthetic way, for example, through rotations, scaling, and changing colors. A trick that I have used is to embed the object I want to identify in different types of backgrounds, and in my use case, it has helped increase accuracy.
  I hope this helps!
  
  
  ---
  
  