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

wandb log artifact fails at end of run #4672

Closed
jveitchmichaelis opened this issue Sep 4, 2021 · 12 comments
Closed

wandb log artifact fails at end of run #4672

jveitchmichaelis opened this issue Sep 4, 2021 · 12 comments
Labels
bug Something isn't working Stale

Comments

@jveitchmichaelis
Copy link
Contributor

jveitchmichaelis commented Sep 4, 2021

🐛 Bug

When training using a wandb sweep, the call to log_artifact at the end of the run fails with a ValueError that the path is not correct.

To Reproduce (REQUIRED)

Run a sweep e.g:

wandb sweep ../configs/sweep.yaml --project <>--name test
wandb agent etc

Example config:

2021-09-04 20:49:21,924 - wandb.wandb_agent - INFO - About to run command: /usr/bin/env python utils/loggers/wandb/sweep.py --anchor_t=2.91 --batch_size=32 --box=0.0296 --cl
s=0.243 --cls_pw=0.631 --copy_paste=0 --data=../configs/dataset_final_ultralytics.yaml --degrees=0.373 --epochs=200 --fl_gamma=0 --fliplr=0.5 --flipud=0.5 --hsv_h=0.0138 --
hsv_s=0.664 --hsv_v=0.464 --img=640 --iou_t=0.2 --lr0=0.0016 --lrf=0.06 --mixup=0.342 --momentum=0.843 --mosaic=1 --obj=0.301 --obj_pw=0.911 --patience=150 --perspective=0 -
-scale=0.898 --shear=0.602 --translate=0.245 --warmup_bias_lr=0.05 --warmup_epochs=5 --warmup_momentum=0.5 --weight_decay=0.00036 --weights=yolov5s.pt --workers=8
wandb: 

Output (presumably at an early-stopping point as the epoch number is always less than max):

    51/199     4.79G   0.02315  0.004203 0.0005895        69       640: 100%|██████████████████████████████████████████████████████████████| 186/186 [00:35<00:00,  5.26it/s]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100%|████████████████████████████████████████████████| 23/23 [00:05<00:00,  4.34it/s]
                 all       1415       3611       0.35      0.351      0.331      0.164
Traceback (most recent call last):
  File "/home/josh/code/yolo/yolov5/utils/loggers/wandb/sweep.py", line 33, in <module>
    sweep()
  File "/home/josh/code/yolo/yolov5/utils/loggers/wandb/sweep.py", line 29, in sweep
    train(hyp_dict, opt, device)
  File "/home/josh/code/yolo/yolov5/train.py", line 421, in train
    callbacks.on_train_end(last, best, plots, epoch)
  File "/home/josh/code/yolo/yolov5/utils/callbacks.py", line 173, in on_train_end
    self.run_callbacks('on_train_end', *args, **kwargs)
  File "/home/josh/code/yolo/yolov5/utils/callbacks.py", line 71, in run_callbacks
    logger['callback'](*args, **kwargs)
  File "/home/josh/code/yolo/yolov5/utils/loggers/__init__.py", line 143, in on_train_end
    wandb.log_artifact(str(best if best.exists() else last), type='model',
  File "/home/josh/anaconda3/envs/yolo/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 2147, in log_artifact
    return self._log_artifact(artifact_or_path, name, type, aliases)
  File "/home/josh/anaconda3/envs/yolo/lib/python3.9/site-packages/wandb/sdk/wandb_run.py", line 2266, in _log_artifact
    artifact, aliases = self._prepare_artifact(
  File "/home/josh/anaconda3/envs/yolo/lib/python3.9/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

wandb: Waiting for W&B process to finish, PID 26001
wandb: Program failed with code 1.  Press ctrl-c to abort syncing.
wandb:
wandb: Find user logs for this run at: /home/josh/code/yolo/yolov5/wandb/run-20210904_151552-m0kgmv8u/logs/debug.log
wandb: Find internal logs for this run at: /home/josh/code/yolo/yolov5/wandb/run-20210904_151552-m0kgmv8u/logs/debug-internal.log
wandb: Run summary:
wandb:                 train/box_loss 0.02315
wandb:                 train/obj_loss 0.0042
wandb:                 train/cls_loss 0.00059
wandb:              metrics/precision 0.3496
wandb:                 metrics/recall 0.35147
wandb:                metrics/mAP_0.5 0.33073
wandb:           metrics/mAP_0.5:0.95 0.164
wandb:                   val/box_loss 0.03803
wandb:                   val/obj_loss 0.00572

Adding a try/except block around the call gives the following path:

runs/train/exp38/weights/last.pt

but the weight folder is empty. So for some reason the run is terminating, but it's not saving the final checkpoint?

Expected behavior

The artifact (e.g. best/last) model is uploaded.

Environment

If applicable, add screenshots to help explain your problem.

  • OS: Ubuntu 18.04
  • GPU: GTX 2070 Super
@jveitchmichaelis jveitchmichaelis added the bug Something isn't working label Sep 4, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2021

👋 Hello @jveitchmichaelis, 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

@jveitchmichaelis thanks for raising this issue!

@AyushExel can you take a look at this please? Thanks!

@AyushExel
Copy link
Contributor

I'll try to reproduce this and push a fix today

@jveitchmichaelis
Copy link
Contributor Author

jveitchmichaelis commented Sep 6, 2021 via email

@AyushExel
Copy link
Contributor

@jveitchmichaelis I wasn't able to reproduce it. I'm currently executing this command from inside the yolov5 folder.

wandb sweep utils/loggers/wandb/sweep.yaml --name sweep_test
wandb agent {sweep id here}

How are you running the sweep? Can you share your sweep.yaml file contents? thanks!

@jveitchmichaelis
Copy link
Contributor Author

jveitchmichaelis commented Sep 6, 2021

Sure, here's the sweep:

# Hyperparameters for training
# To set range- 
# Provide min and max values as:
#      parameter:
#         
#         min: scalar
#         max: scalar
# OR
#
# Set a specific list of search space-
#     parameter: 
#         values: [scalar1, scalar2, scalar3...]
#         
# You can use grid, bayesian and hyperopt search strategy 
# For more info on configuring sweeps visit - https://docs.wandb.ai/guides/sweeps/configuration

program: utils/loggers/wandb/sweep.py
method: grid
metric:
  name: metrics/mAP_0.5
  goal: maximize

parameters:
  # hyperparameters: set either min, max range or values list
  weights:
    value: yolov5s.pt
  data:
    values: ["../configs/dataset_10.yaml", "../configs/dataset_5.yaml", "../configs/dataset.yaml"]
  batch_size:
    values: [4, 8, 16]
  epochs:
    distribution: constant
    value: 150
  workers:
    distribution: constant
    value: 2
  img:
    distribution: constant
    value: 640
  lr0:
    distribution: constant
    value: 0.0016
  lrf: # final cyclic training rate, lr0 * lrf!
    distribution: constant
    value: 0.06
  momentum:
    distribution: constant
    value: 0.843
  weight_decay:
    distribution: constant
    value: 0.00036
  warmup_epochs:
    distribution: constant
    value: 5
  warmup_momentum:
    distribution: constant
    value: 0.5
  warmup_bias_lr:
    distribution: constant
    value: 0.05
  box:
    distribution: constant
    value: 0.0296
  cls:
    distribution: constant
    value: 0.243
  cls_pw:
    distribution: constant
    value: 0.631
  obj:
    distribution: constant
    value: 0.301
  obj_pw:
    distribution: constant
    value: 0.911
  iou_t:
    distribution: constant
    value: 0.2
  anchor_t:
    distribution: constant
    value: 2.91

  # Augmentation
  fl_gamma:
    distribution: constant
    value: 0.0
  hsv_h:
    distribution: constant
    value: 0.0138
  hsv_s:
    distribution: constant
    value: 0.664
  hsv_v:
    distribution: constant
    value: 0.464
  degrees:
    distribution: constant
    value: 0.373
  translate:
    distribution: constant
    value: 0.245
  scale:
    distribution: constant
    value: 0.898
  shear:
    distribution: constant
    value: 0.602
  perspective:
    distribution: constant
    value: 0.0
  flipud:
    distribution: constant
    value: 0.5
  fliplr:
    distribution: constant
    value: 0.5
  mosaic:
    distribution: constant
    value: 1.0
  mixup:
    distribution: constant
    value: 0.342
  copy_paste:
    distribution: constant
    value: 0.0

and yep, I'm running from the folder with:

wandb sweep ../configs/sweep_constant.yaml  --name etc #above
wandb agent {sweep id}

I have yolov5 as a submodule inside my dataset repository, but I don't think it should make a difference

@AyushExel
Copy link
Contributor

Thanks I'm trying to repro. I'll update soon

@AyushExel
Copy link
Contributor

@jveitchmichaelis Okay I tried running the sweep for 150 epochs and I didn't see any error. Is this error reproducible from your end? Run the same command again to repro ( if you haven't done this already)

@jveitchmichaelis
Copy link
Contributor Author

jveitchmichaelis commented Sep 9, 2021

Yeah I'll try again. There are some other odd things which I'm trying to dig into. Here's an output from a non-sweep run:

python train.py --img 640 --device 0 --batch 8 --epochs 200 --workers 4 --data ../configs/final_ultralytics_5.yaml --weights yolov5m.pt --hyp ../configs/hyp.finetune.yaml --entity <me> --project project_name--save_period 10

the run stops early (fine):


     Epoch   gpu_mem       box       obj       cls    labels  img_size
    32/199     6.01G   0.01985  0.003756 0.0005924         2       640: 100%|██████████████████████████████████████████████████████████████████████| 742/742 [02:59<00:00,  4.14it/s]
               Class     Images     Labels          P          R     mAP@.5 mAP@.5:.95: 100%|████████████████████████████████████████████████████████| 89/89 [00:13<00:00,  6.60it/s]
                 all       1415       3611      0.384       0.35      0.335       0.15
EarlyStopping patience 30 exceeded, stopping training.

33 epochs completed in 1.782 hours.
Optimizer stripped from <project_name>/exp10/weights/last.pt, 93.7MB
Optimizer stripped from <project_name>/exp10/weights/best.pt, 93.7MB

wandb: Waiting for W&B process to finish, PID 27174
wandb: Program ended successfully.

...

you can see that the weights are created - here's the output folder:

(yolo) user@mimir:~/code/yolov5/<project_name>/exp10$ tree -L 2
.
├── events.out.tfevents.1631138661.mimir.27098.0
├── hyp.yaml
├── labels_correlogram.jpg
├── labels.jpg
├── opt.yaml
├── results.csv
├── results.png
├── train_batch0.jpg
├── train_batch1.jpg
├── train_batch2.jpg
└── weights
    ├── best.pt
    └── last.pt

1 directory, 12 files

So that's OK. But oddly there is no confusion matrix, per-class-AP is not printed to the log file, and I suppose as a result, the matrix image doesn't get uploaded to wandb either.

EDIT: It looks like this got fixed a few days ago with updates to the early stopping functionality. I'll test again...

@glenn-jocher
Copy link
Member

glenn-jocher commented Sep 9, 2021

@jveitchmichaelis some of your questions are addressed in EarlyStopping updates PR #4679, which increases the default patience to 100 and fixes the lack of validation results you mentioned (no confusion matrix etc.)

@jveitchmichaelis
Copy link
Contributor Author

jveitchmichaelis commented Sep 9, 2021

@glenn-jocher Yep - I just saw, thanks! The fix was only a few days ago, so I've re-pulled and will test again. It's possible that the same issue was causing weights to not be created.

@AyushExel - I'll try a sweep with e.g. 1 epoch and see if it still occurs

@github-actions
Copy link
Contributor

github-actions bot commented Oct 10, 2021

👋 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 ⭐!

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

No branches or pull requests

3 participants