ultralytics / yolov5

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

The loss of training verification set on 3080ti graphics card is always 0(To be more precise, is empty.) #12291

Closed StudyingLover closed 1 year ago

StudyingLover commented 1 year ago

Search before asking

YOLOv5 Component

Training

Bug

Hello,I am a loyal user of yolov5. Recently I was doing an experiment using yolov5 for target detection. I use a 3080ti cloud server and a 4060 personal computer for training. In addition, I made modifications to the model. The modified files are as follows.I named it small.yaml.

# parameters
nc: 1  # number of classes
depth_multiple: 0.33  # model depth multiple
width_multiple: 0.50  # layer channel multiple

# anchors
anchors:
  - [5,6, 8,14, 15,11]  #4
  - [10,13, 16,30, 33,23]  # P3/8
  - [30,61, 62,45, 59,119]  # P4/16
  - [116,90, 156,198, 373,326]  # P5/32

backbone:
  # [from, number, module, args]
  [[-1, 1, Focus, [64, 3]],  # 0-P1/2
   [-1, 1, Conv, [128, 3, 2]],  # 1-P2/4
   [-1, 3, C3, [128]],
   [-1, 1, Conv, [256, 3, 2]],  # 3-P3/8
   [-1, 9, C3, [256]],
   [-1, 1, Conv, [512, 3, 2]],  # 5-P4/16
   [-1, 9, C3, [512]],
   [-1, 1, Conv, [1024, 3, 2]],  # 7-P5/32
   [-1, 1, SPP, [1024, [5, 9, 13]]],
   [-1, 3, C3, [1024, False]],  # 9
  ]

# YOLOv5 head
head:
  [[-1, 1, Conv, [512, 1, 1]],#20*20
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 6], 1, Concat, [1]],  # cat backbone P4
   [-1, 3, C3, [512, False]],  # 13

   [-1, 1, Conv, [512, 1, 1]], #40*40 14
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 4], 1, Concat, [1]],  # cat backbone P3   80*80
   [-1, 3, C3, [512, False]],  # 17 (P3/8-small)  80*80

   [-1, 1, Conv, [256, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 2], 1, Concat, [1]],  # cat backbone P3
   [-1, 3, C3, [256, False]],  # 17 (P3/8-small)21

   [-1, 1, Conv, [256, 3, 2]],
   [[-1, 18], 1, Concat, [1]],  # cat head P4
   [-1, 3, C3, [256, False]],  # 20 (P4/16-medium)24

   [-1, 1, Conv, [256, 3, 2]],  #22   80*80
   [[-1, 14], 1, Concat, [1]], #23 80*80
   [-1, 3, C3, [512, False]], #24 80*80

   [-1, 1, Conv, [512, 3, 2]],
   [[-1, 10], 1, Concat, [1]],  # cat head P5
   [-1, 3, C3, [1024, False]],  # 23 (P5/32-large)

   [[21, 24, 27,30], 1, Detect, [nc, anchors]],  # Detect(P3, P4, P5)
  ]

I also created a data.yaml and placed the information of my dataset

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: /root/data/data  # dataset root dir
train: train  # train images (relative to 'path') 128 images
val: val  # val images (relative to 'path') 128 images
test: val # test images (optional)

# Classes (80 COCO classes)
names:
  0: drone

I ran the following two commands on the server to train the model

python train.py --data data.yaml --epochs 10 --batch-size -1 --cfg small.yaml

and

python train.py --data data.yaml --epochs 10 --batch-size -1

I got result.png as follows results

results

Maybe you think this is because the training times are too few. I will provide you with the training results on 4090 below with samll.yaml. results

In order to avoid this, I used 3080 to train the same number of times, with and without small.yaml results results

Environment

4090 Python Version: 3.11.3 Torch Version: 2.0.1+cu117 System Version: Linux YOLOV5: lealatest

3080ti Python Version: 3.8.10 Torch Version: 1.9.0+cu111 System Version: Linux YOLOV5: commit hash is 50ff6eee31c72fe88bdd35fc7299b201cce0e9a6

3080 Python Version: 3.8.10 Torch Version: 1.9.0+cu111 System Version: Linux YOLOV5: lealatest

Minimal Reproducible Example

I made modifications to the model. The modified files are as follows.I named it small.yaml.

# parameters
nc: 1  # number of classes
depth_multiple: 0.33  # model depth multiple
width_multiple: 0.50  # layer channel multiple

# anchors
anchors:
  - [5,6, 8,14, 15,11]  #4
  - [10,13, 16,30, 33,23]  # P3/8
  - [30,61, 62,45, 59,119]  # P4/16
  - [116,90, 156,198, 373,326]  # P5/32

backbone:
  # [from, number, module, args]
  [[-1, 1, Focus, [64, 3]],  # 0-P1/2
   [-1, 1, Conv, [128, 3, 2]],  # 1-P2/4
   [-1, 3, C3, [128]],
   [-1, 1, Conv, [256, 3, 2]],  # 3-P3/8
   [-1, 9, C3, [256]],
   [-1, 1, Conv, [512, 3, 2]],  # 5-P4/16
   [-1, 9, C3, [512]],
   [-1, 1, Conv, [1024, 3, 2]],  # 7-P5/32
   [-1, 1, SPP, [1024, [5, 9, 13]]],
   [-1, 3, C3, [1024, False]],  # 9
  ]

# YOLOv5 head
head:
  [[-1, 1, Conv, [512, 1, 1]],#20*20
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 6], 1, Concat, [1]],  # cat backbone P4
   [-1, 3, C3, [512, False]],  # 13

   [-1, 1, Conv, [512, 1, 1]], #40*40 14
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 4], 1, Concat, [1]],  # cat backbone P3   80*80
   [-1, 3, C3, [512, False]],  # 17 (P3/8-small)  80*80

   [-1, 1, Conv, [256, 1, 1]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [[-1, 2], 1, Concat, [1]],  # cat backbone P3
   [-1, 3, C3, [256, False]],  # 17 (P3/8-small)21

   [-1, 1, Conv, [256, 3, 2]],
   [[-1, 18], 1, Concat, [1]],  # cat head P4
   [-1, 3, C3, [256, False]],  # 20 (P4/16-medium)24

   [-1, 1, Conv, [256, 3, 2]],  #22   80*80
   [[-1, 14], 1, Concat, [1]], #23 80*80
   [-1, 3, C3, [512, False]], #24 80*80

   [-1, 1, Conv, [512, 3, 2]],
   [[-1, 10], 1, Concat, [1]],  # cat head P5
   [-1, 3, C3, [1024, False]],  # 23 (P5/32-large)

   [[21, 24, 27,30], 1, Detect, [nc, anchors]],  # Detect(P3, P4, P5)
  ]

run

python train.py --data data.yaml --epochs 10 --batch-size -1 --cfg small.yaml

and

python train.py --data data.yaml --epochs 10 --batch-size -1

Additional

No response

Are you willing to submit a PR?

github-actions[bot] commented 1 year ago

👋 Hello @StudyingLover, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics
StudyingLover commented 1 year ago

To be more precise, the loss on the validation set is empty.

StudyingLover commented 1 year ago

After checking, we found that there was a problem with the autodl.com mirror. Delete the code and re-git clone to solve the problem.

glenn-jocher commented 1 year ago

@StudyingLover thank you for bringing this issue to our attention. We apologize for any inconvenience you may have experienced.

Based on the information you provided, it seems that there was an issue with the autodl.com mirror. To address this problem, we recommend deleting the existing code and re-cloning the repository to ensure a fresh copy.

Please follow these steps to resolve the problem:

  1. Delete the current YOLOv5 code from your system.
  2. Clone the YOLOv5 repository again using the following command:
    git clone https://github.com/ultralytics/yolov5

This should provide you with a clean copy of the YOLOv5 codebase and resolve the issue you encountered with the loss on the validation set being empty.

If you have any further questions or need additional assistance, please feel free to ask.