ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
49.63k stars 16.1k forks source link

Val Loss smaller than Train Loss #7017

Closed st162053 closed 2 years ago

st162053 commented 2 years ago

Search before asking

Question

Screenshot 2022-03-17 103435 Hi, as seen in the graph my val losses are constantly lower than my train losses. Why is that and is val>train a sign for overfitting? Or does it only occur with the increase of the val losses? Thanks

Additional

No response

glenn-jocher commented 2 years ago

@st162053 this is normal. Train images are augmented (harder) and the val images are not (easier).

YOLOv5 🚀 applies online imagespace and colorspace augmentations in the trainloader (but not the val_loader) to present a new and unique augmented Mosaic (original image + 3 random images) each time an image is loaded for training. Images are never presented twice in the same way.

YOLOv5 augmentation

Augmentation Hyperparameters

The hyperparameters used to define these augmentations are in your hyperparameter file (default data/hyp.scratch.yaml) defined when training:

python train.py --hyp hyp.scratch-low.yaml

https://github.com/ultralytics/yolov5/blob/b94b59e199047aa8bf2cdd4401ae9f5f42b929e6/data/hyps/hyp.scratch-low.yaml#L6-L34

Augmentation Previews

You can view the effect of your augmentation policy in your train_batch*.jpg images once training starts. These images will be in your train logging directory, typically yolov5/runs/train/exp:

train_batch0.jpg shows train batch 0 mosaics and labels:

YOLOv5 Albumentations Integration

YOLOv5 🚀 is now fully integrated with Albumentations, a popular open-source image augmentation package. Now you can train the world's best Vision AI models even better with custom Albumentations 😃!

PR https://github.com/ultralytics/yolov5/pull/3882 implements this integration, which will automatically apply Albumentations transforms during YOLOv5 training if albumentations>=1.0.3 is installed in your environment. See https://github.com/ultralytics/yolov5/pull/3882 for full details.

Example train_batch0.jpg on COCO128 dataset with Blur, MedianBlur and ToGray. See the YOLOv5 Notebooks to reproduce: Open In Colab Open In Kaggle

Good luck 🍀 and let us know if you have any other questions!

st162053 commented 2 years ago

Great. Thank you! Would you recommend using an annotated test dataset after train and validation for evaluation of the model?

glenn-jocher commented 2 years ago

@st162053 main purpose of a test set is competition holdout with no public labels.