ultralytics / yolov5

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

Continue training yolov5 with checkpoint crowdhuman_yolov5m.pt #4585

Closed viethoang303 closed 3 years ago

viethoang303 commented 3 years ago

Hi everyone, I have just built a dataset from MOT17 Challenge dataset, and its format is similar the format that for training yolov5. I tried to training yolov5 with checkpoint yolov5m.pt on google colab and it worked. But when I trained with checkpoint crowdhuman_yolov5m.pt:

!python train.py --img 640 --batch 16 --epochs 10 --data data.yaml --weights crowdhuman_yolov5m.pt --cache

I received an error:

"RuntimeError: The size of tensor a (21) must match the size of tensor b (18) at non-singleton dimension 0"

Anyone can help me to fix this error. Thank you

github-actions[bot] commented 3 years ago

👋 Hello @viethoang303, 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 screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

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

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

CI CPU testing

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

glenn-jocher commented 3 years ago

@viethoang303 👋 Hello! Thanks for asking about resuming training. YOLOv5 🚀 Learning Rate (LR) schedulers follow predefined LR curves for the fixed number of --epochs defined at training start (default=300), and are designed to fall to a minimum LR on the final epoch for best training results. For this reason you can not modify the number of epochs once training has started.

LR Curves

If your training was interrupted for any reason you may continue where you left off using the --resume argument. If your training fully completed, you can start a new training from any model using the --weights argument. Examples:

Resume Single-GPU

You may not change settings when resuming, and no additional arguments other than --resume should be passed, with an optional path to the checkpoint you'd like to resume from. If no checkpoint is passed the most recently updated last.pt in your yolov5/ directory is automatically found and used:

python train.py --resume  # automatically find latest checkpoint (searches yolov5/ directory)
python train.py --resume path/to/last.pt  # specify resume checkpoint

Resume Multi-GPU

Multi-GPU DDP trainings must be resumed with the same GPUs and DDP command, i.e. assuming 8 GPUs:

python -m torch.distributed.run --nproc_per_node 8 train.py --resume  # resume latest checkpoint
python -m torch.distributed.run --nproc_per_node 8 train.py --resume path/to/last.pt  # specify resume checkpoint

Start from Pretrained

If you would like to start training from a fully trained model, use the --weights argument, not the --resume argument:

python train.py --weights path/to/best.pt  # start from pretrained model

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

github-actions[bot] commented 3 years ago

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!

HeChengHui commented 2 years ago

@glenn-jocher I also encountered the same problem when trying to train using crowdhuman_yolov5m.pt using the visdrone dataset on windows10. cmd: python train.py --data VisDrone.yaml --weights crowdhuman_yolov5m.pt --batch-size -1 error msg:

module 'signal' has no attribute 'SIGALRM'

AutoAnchor: 3.29 anchors/target, 0.998 Best Possible Recall (BPR). Current anchors are a good fit to dataset
Image sizes 640 train, 640 val
Using 8 dataloader workers
Logging results to runs\train\exp3
Starting training for 300 epochs...

     Epoch   gpu_mem       box       obj       cls    labels  img_size
  0%|          | 0/540 [00:01<?, ?it/s]
Traceback (most recent call last):
  File "train.py", line 627, in <module>
    main(opt)
  File "train.py", line 524, in main
    train(opt.hyp, opt, device, callbacks)
  File "train.py", line 332, in train
    scaler.step(optimizer)  # optimizer.step
  File "D:\STUDIES\Anaconda\envs\YoloV5\lib\site-packages\torch\cuda\amp\grad_scaler.py", line 338, in step
    retval = self._maybe_opt_step(optimizer, optimizer_state, *args, **kwargs)
  File "D:\STUDIES\Anaconda\envs\YoloV5\lib\site-packages\torch\cuda\amp\grad_scaler.py", line 285, in _maybe_opt_step
    retval = optimizer.step(*args, **kwargs)
  File "D:\STUDIES\Anaconda\envs\YoloV5\lib\site-packages\torch\optim\lr_scheduler.py", line 65, in wrapper
    return wrapped(*args, **kwargs)
  File "D:\STUDIES\Anaconda\envs\YoloV5\lib\site-packages\torch\optim\optimizer.py", line 88, in wrapper
    return func(*args, **kwargs)
  File "D:\STUDIES\Anaconda\envs\YoloV5\lib\site-packages\torch\autograd\grad_mode.py", line 28, in decorate_context
    return func(*args, **kwargs)
  File "D:\STUDIES\Anaconda\envs\YoloV5\lib\site-packages\torch\optim\sgd.py", line 136, in step
    F.sgd(params_with_grad,
  File "D:\STUDIES\Anaconda\envs\YoloV5\lib\site-packages\torch\optim\_functional.py", line 173, in sgd
    buf.mul_(momentum).add_(d_p, alpha=1 - dampening)
RuntimeError: The size of tensor a (21) must match the size of tensor b (45) at non-singleton dimension 0
glenn-jocher commented 2 years ago

@HeChengHui 3rd party weights are your responsibility. VisDrone trains correctly from official weights (our responsibility):

Screen Shot 2021-12-30 at 1 33 21 PM

We've created a few short guidelines below to help users provide what we need in order to get started investigating a possible problem.

How to create a Minimal, Reproducible Example

When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:

For Ultralytics to provide assistance your code should also be:

If you believe your problem meets all the above criteria, please close this issue and raise a new one using the 🐛 Bug Report template with a minimum reproducible example to help us better understand and diagnose your problem.

Thank you! 😃

HeChengHui commented 2 years ago

So the crowdhuman model might contain some error?

youonlytrackonce commented 2 years ago

So the crowdhuman model might contain some error?

Hello,

did you find any solution?