Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evolve failing with wandb activated due to model not being saved #4604

Closed
adrigrillo opened this issue Aug 30, 2021 · 14 comments · Fixed by #4611
Closed

Evolve failing with wandb activated due to model not being saved #4604

adrigrillo opened this issue Aug 30, 2021 · 14 comments · Fixed by #4611
Labels
bug Something isn't working

Comments

@adrigrillo
Copy link

🐛 Bug

The evolution process fails at the end of the first iteration due to wandb failing to found last.pt, which does not exist. The problem is originated in the callback to end the training, that calls the wandb logger and which tries to upload the weight files.

Here a doubt arises, why is the model not saved, I mean the last.pt, during the evolution process. In this way, the trained model cannot be recovered after training.

To Reproduce (REQUIRED)

Input:

Just execute the training process with the 'evolve' flag activated and wandb configured.

Output:

1 epochs completed in 0.026 hours.
Traceback (most recent call last):
  File "/home/uasteam/Workspace/ARTINDET/shipdetection/yolov5/train.py", line 611, in <module>
    main(opt)
  File "/home/uasteam/Workspace/ARTINDET/shipdetection/yolov5/train.py", line 589, in main
    results = train(hyp.copy(), opt, device)
  File "/home/uasteam/Workspace/ARTINDET/shipdetection/yolov5/train.py", line 421, in train
    callbacks.on_train_end(last, best, plots, epoch)
  File "/home/uasteam/Workspace/ARTINDET/shipdetection/yolov5/utils/callbacks.py", line 173, in on_train_end
    self.run_callbacks('on_train_end', *args, **kwargs)
  File "/home/uasteam/Workspace/ARTINDET/shipdetection/yolov5/utils/callbacks.py", line 71, in run_callbacks
    logger['callback'](*args, **kwargs)
  File "/home/uasteam/Workspace/ARTINDET/shipdetection/yolov5/utils/loggers/__init__.py", line 142, in on_train_end
    wandb.log_artifact(str(best if best.exists() else last), type='model',
  File "/home/uasteam/anaconda3/envs/yolo-boats/lib/python3.8/site-packages/wandb/sdk/wandb_run.py", line 2147, in log_artifact
    return self._log_artifact(artifact_or_path, name, type, aliases)
  File "/home/uasteam/anaconda3/envs/yolo-boats/lib/python3.8/site-packages/wandb/sdk/wandb_run.py", line 2266, in _log_artifact
    artifact, aliases = self._prepare_artifact(
  File "/home/uasteam/anaconda3/envs/yolo-boats/lib/python3.8/site-packages/wandb/sdk/wandb_run.py", line 2343, in _prepare_artifact
    raise ValueError(
ValueError: path must be a file, directory or externalreference like s3://bucket/path

Expected behavior

I expect the last.pt to be saved and the training to continue.

Environment

  • OS: Ubuntu 18.04.5 LTS
  • GPU: GeForce GTX 1080 Ti/PCIe/SSE2
@adrigrillo adrigrillo added the bug Something isn't working label Aug 30, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Aug 30, 2021

👋 Hello @adrigrillo, 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
Copy link
Member

@adrigrillo thanks for the bug report! To answer your question weights are not saved because the output of evolution is the maximum fitness evolved hyperparameters (in hyp.evolved.yaml), not any particular generation's weights. Also practically speaking, if we evolve 300 generations we don't want 600 best.pt and last.pt checkpoints occupying user's hard drives.

@AyushExel can you look into this? We probably want to filter the upload artifact list to prevent attempting uploading non-existing files, or simply place the upload under an if file.exists(): statement. I do this when logging images to TensorBoard for example here on L131:

files = ['results.png', 'confusion_matrix.png', *[f'{x}_curve.png' for x in ('F1', 'PR', 'P', 'R')]]
files = [(self.save_dir / f) for f in files if (self.save_dir / f).exists()] # filter
if self.tb:
from PIL import Image
import numpy as np
for f in files:
self.tb.add_image(f.stem, np.asarray(Image.open(f)), epoch, dataformats='HWC')

This is effectively silent error handling, so maybe a warning would be appropriate.

@adrigrillo
Copy link
Author

Thanks to you for the fast response and this great repo.

With regard to the checkpoint saving, saving 300 last.pt is not desirable, I understand.
However, it could be interesting to just save the best choice, similarly to the best.pt when training.
That is, just keep the checkpoint of the best training during the evolution process.
I do not know if this sound interesting for you or if it can be implemented at all, I may help with that if so.

Thanks again for the support 😄

@AyushExel
Copy link
Contributor

@glenn-jocher I'll put up a fix for this today

@glenn-jocher
Copy link
Member

@AyushExel thanks!

@AyushExel
Copy link
Contributor

@glenn-jocher every evolve operation should start a new wandb run right? So the logic in the logger class should be like this:

           if not self.opt.evolve:
                wandb.log_artifact(str(best if best.exists() else last), type='model',
                                   name='run_' + self.wandb.wandb_run.id + '_model',
                                   aliases=['latest', 'best', 'stripped'])
                self.wandb.finish_run()
            else:
                self.wandb = WandbLogger(self.opt)

Here, we're starting a new run if the job type is evolve. If this seems the correct logic for evolve operation, I'll go ahead and make a PR

@glenn-jocher
Copy link
Member

@AyushExel yes each generation should be a new W&B run, i.e. like this more or less from earlier https://wandb.ai/glenn-jocher/COCO128_evolve

@glenn-jocher
Copy link
Member

@adrigrillo good news 😃! Your original issue may now be fixed ✅ in PR #4611 by @AyushExel . To receive this update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload with model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

@adrigrillo
Copy link
Author

Thanks for the support!! Great work! ❤️

@adrigrillo
Copy link
Author

Hello again,

I have started to train a network using evolution with the last fixes, however, I am seeing in W&B panel some entries, which last around 6 seconds, that are not real trainings and that have the same hyperparameters as the following training (which is the proper training). I attach the current status of the W&B panel:

imagen

In this case, I am running my fourth evolution training, but there are this other entries (the ones with a tick) that have the same hyperparameters that the one being trained.

@AyushExel
Copy link
Contributor

@adrigrillo I think these are runs from a previous evolution. By default, the evolution runs are all logged in the project called evolve. Right now, the easiest way to fix this would be delete all the existing runs in the project evolve before you runs another evolve operation.

@glenn-jocher I think this is related to train.py more that W&B. The evolve operation project name is hardcoded to runs/evolve. Can we use the same logic to increment that as it is done from runs like exp, exp2 .. and evolve, evolve2..?

@adrigrillo
Copy link
Author

@AyushExel this is my first evolution execution, I removed all the data of previous ones.
By the way, the training has continued, it is the seventh evolution, and this seems like an exponential process.
When I have connected to see the status this morning, there was like 15 entries like that, so the number of them created in each iteration increases. I will send a screenshot of the next iteration when it starts, so you can have a better overview.

@adrigrillo
Copy link
Author

adrigrillo commented Sep 1, 2021

Here it is an example of the last evolution epoch. The youthful-frost-31 finished and the scarlet-cloud-38 is the next generation, however, some entries were created with the same hyperparameter than scarlet-cloud-38 but not trained.
imagen

On the other hand, the evolve.csv is fine and its content is the following:

   metrics/precision,      metrics/recall,     metrics/mAP_0.5,metrics/mAP_0.5:0.95,        val/box_loss,        val/obj_loss,        val/cls_loss,                 lr0,                 lrf,            momentum,        weight_decay,       warmup_epochs,     warmup_momentum,      warmup_bias_lr,                 box,                 cls,              cls_pw,                 obj,              obj_pw,               iou_t,            anchor_t,            fl_gamma,               hsv_h,               hsv_s,               hsv_v,             degrees,           translate,               scale,               shear,         perspective,              flipud,              fliplr,              mosaic,               mixup,          copy_paste,             anchors
             0.81925,             0.70942,             0.75805,             0.27809,            0.036646,           0.0099101,                   0,              0.0032,                0.12,               0.843,             0.00036,                   2,                 0.5,                0.05,              0.0296,               0.243,               0.631,               0.301,               0.911,                 0.2,                2.91,                   0,              0.0138,               0.664,               0.464,               0.373,               0.245,               0.898,               0.602,                   0,             0.00856,                 0.5,                   0,                   0,                   0,                   3
             0.79268,              0.6951,              0.7431,             0.27521,            0.031051,            0.010902,                   0,              0.0032,             0.08043,             0.83663,             0.00033,                   2,                 0.5,                0.05,             0.02471,               0.243,             0.61043,             0.31605,             0.91078,                 0.2,                2.91,                   0,              0.0138,             0.63292,             0.39487,               0.373,             0.24776,             0.78212,             0.64656,                   0,             0.00856,             0.55101,                   0,                   0,                   0,              2.6399
             0.81605,             0.70202,             0.74504,             0.26297,            0.037137,            0.009993,                   0,             0.00324,             0.12941,              0.8351,             0.00034,              1.8201,             0.48677,              0.0506,              0.0296,             0.27147,               0.631,             0.30654,             0.92631,                 0.2,                2.91,                   0,              0.0138,             0.68216,             0.46771,             0.37864,             0.23707,                 0.9,             0.62485,                   0,             0.00856,             0.53214,                   0,                   0,                   0,              2.9352
             0.79261,             0.70447,             0.74964,             0.28126,            0.036218,           0.0088652,                   0,             0.00333,             0.12081,             0.83871,             0.00033,              1.8563,             0.52175,             0.04418,             0.02946,             0.26268,               0.631,             0.28001,             0.88013,                 0.2,              2.8398,                   0,              0.0138,                 0.9,             0.32603,             0.35549,             0.27948,                 0.9,             0.82348,                   0,             0.00856,             0.49653,                   0,                   0,                   0,              2.9352
              0.8213,             0.71487,             0.76806,             0.28912,            0.035931,           0.0088009,                   0,             0.00333,             0.12081,             0.83844,             0.00033,              1.8557,             0.52147,             0.04418,             0.02946,             0.26268,             0.63098,                0.28,             0.88013,                 0.2,                2.84,                   0,              0.0138,                 0.9,             0.32606,             0.35556,             0.27958,                 0.9,             0.82356,                   0,             0.00856,             0.49682,                   0,                   0,                   0,              2.9347
             0.82111,             0.72178,             0.76718,             0.28682,            0.036201,           0.0088806,                   0,             0.00333,             0.12486,             0.85711,             0.00037,              2.0089,             0.52175,             0.03742,             0.02946,             0.30368,             0.65203,             0.28479,             0.88013,                 0.2,              3.2728,                   0,              0.0138,             0.68502,             0.36822,             0.33785,             0.30277,                 0.9,             0.74634,                   0,             0.00856,             0.60786,                   0,                   0,                   0,              3.2501
             0.82704,             0.70128,             0.75458,             0.27516,            0.037025,           0.0074416,                   0,             0.00324,             0.12941,              0.8338,             0.00042,              1.7072,             0.48477,             0.05007,              0.0296,             0.30891,             0.73137,             0.22803,             0.92573,                 0.2,              2.8161,                   0,              0.0138,             0.60412,             0.38516,             0.39254,             0.28341,             0.77613,             0.63828,                   0,             0.00856,             0.50556,                   0,                   0,                   0,              3.5649

@glenn-jocher
Copy link
Member

@AyushExel --evolve will log locally to runs/evolve/exp with incrementing exp names, i.e. in our colab notebook you can run 3 independent evolutions in series (each for 4 generations) which will log to runs/evolve/exp, runs/evolve/exp2, runs/evolve/exp3:
https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb

!python train.py --img 640 --batch 16 --epochs 2 --data coco128.yaml --weights yolov5s.pt --cache --evolve 4
!python train.py --img 640 --batch 16 --epochs 2 --data coco128.yaml --weights yolov5s.pt --cache --evolve 4
!python train.py --img 640 --batch 16 --epochs 2 --data coco128.yaml --weights yolov5s.pt --cache --evolve 4

Screenshot 2021-09-01 at 22 22 37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants