ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.56k stars 16.31k forks source link

wandb log artifact fails at end of run #4672

Closed jveitchmichaelis closed 3 years ago

jveitchmichaelis commented 3 years ago

πŸ› 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.

github-actions[bot] commented 3 years ago

πŸ‘‹ 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 commented 3 years ago

@jveitchmichaelis thanks for raising this issue!

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

AyushExel commented 3 years ago

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

jveitchmichaelis commented 3 years ago

For what it's worth, checkpoints are saved if I run training directly (eg python train.py)

On Mon, Sep 6, 2021, 21:32 Ayush Chaurasia @.***> wrote:

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

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ultralytics/yolov5/issues/4672#issuecomment-913499394, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYDMJYWSPOT4JGKN2YOFQTUASDDZANCNFSM5DNM5ACQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

AyushExel commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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

AyushExel commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

@jveitchmichaelis some of your questions are addressed in EarlyStopping updates PR https://github.com/ultralytics/yolov5/pull/4679, which increases the default patience to 100 and fixes the lack of validation results you mentioned (no confusion matrix etc.)

jveitchmichaelis commented 3 years ago

@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[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 ⭐!