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

Weights & Biases (W&B) Feature Addition #1235

Merged
merged 18 commits into from
Oct 31, 2020
Merged

Weights & Biases (W&B) Feature Addition #1235

merged 18 commits into from
Oct 31, 2020

Conversation

AyushExel
Copy link
Contributor

@AyushExel AyushExel commented Oct 28, 2020

What does this PR do?

This is a cleaned-up and updated version of this PR #1108 which adds W&B logging support.
Updates:

  • The code no longer typecasts co-ordinates into float before passing them to the logging dictionary.
  • Reformatted the code
    Some of the import statement orders didn't pass through the PEP8 linter but these were not related to the changes I have made to I didn't edit them.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Enhanced YOLOv5 logging with Weights & Biases integration for better experiment tracking and visualization 📈.

📊 Key Changes

  • Added Weights & Biases (wandb) logging as a dependency in requirements.txt.
  • Included an option in test.py to log images with predictions during testing.
  • Updated train.py function signature to accept a wandb parameter for logging.
  • Initialized wandb logging in train.py to track experiments and log model performance metrics and hyperparameters.
  • Implemented functionality to save wandb run ID in checkpoints to resume logging from a specific point.
  • Provided an option in the argument parser of train.py to set the number of images logged to wandb.

🎯 Purpose & Impact

  • Enhanced Experiment Tracking: Enabling wandb integration supports researchers and developers in tracking experiments, comparing results, and visualizing model performance more effectively.
  • Better Visualization: Logging images with predictions allows for quick and easy qualitative analysis of the model's performance.
  • Streamlined Workflows: Saving the wandb run ID in checkpoints allows users to continue logging from a specific point without starting a new logging instance, ensuring continuity in metric tracking.
  • Customization: Users can customize the number of images they want to log via the --log-imgs command-line argument, tailoring the verbosity of visual logging to their needs.

In summary, these updates will make it simpler for users to monitor, analyze, and share their YOLOv5 model training and testing processes, promoting more informed and iterative machine learning development. 🚀

@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 31, 2020

@AyushExel I noticed test.py imports wandb directly without a try statement. I'm surprised CI tests are passing like this, I would have thought this would produce an error. Will investigate.

EDIT: the import is inside an if, perhaps this is the reason.

@AyushExel
Copy link
Contributor Author

AyushExel commented Oct 31, 2020

@AyushExel I noticed test.py imports wandb directly without a try statement. I'm surprised CI tests are passing like this, I would have thought this would produce an error. Will investigate.

EDIT: the import is inside an if, perhaps this is the reason.

@glenn-jocher It won't produce an error. If wandb is not installed num_predictions will be set to 0 in train.py, which is also it's default value . And wandb will be imported in test.py only if num_predictions is greater than 0. You can test it on your end as well

@glenn-jocher
Copy link
Member

@AyushExel I've done a general reorganization of the code:

  • removed seperate wandb logging boolean, now we simply use wandb package treated as a boolean (same handling as tb).
  • resume functionality moved to ckpt resume statement, cleaned up and shortened.
  • project has been seet to logdir rather than opt.name. This is very important since it automatically includes incremented experiment numbers, and it also includes opt.name if it is found: i.e. logdir=runs/exp0 or runs/exp0_name
  • wandb importing logic has been moved inside if opt.global_rank in [-1, 0]: statement to prevent multiple loggers opening up on multi-GPU training.
  • default image logging count reduced from 50 images to 10 to reduce added time to about 1.0 seconds from 5 seconds.

train.py Outdated Show resolved Hide resolved
@glenn-jocher glenn-jocher changed the title Add W&B metric and Bounding Box Logging Weights & Biases (W&B) Logging Feature Addition Oct 31, 2020
@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 31, 2020

@AyushExel I think I've completed all of my updates. Can you review and verify that I haven't broken anything inadvertently?

This should work in multi-gpu now, but I will test today to verify. CI tests only run on CPU, single-GPU and multi-GPU testing is done by hand at the moment.

train.py Outdated Show resolved Hide resolved
train.py Outdated Show resolved Hide resolved
train.py Outdated Show resolved Hide resolved
train.py Outdated Show resolved Hide resolved
@AyushExel
Copy link
Contributor Author

@glenn-jocher I'm getting another error now:

 File "train.py", line 342, in train
    wandb.log({tag: x})  # W&B
 raise wandb.Error("You must call wandb.init() before {}()".format(name))
wandb.errors.error.Error: You must call wandb.init() before wandb.log()
Internal process exited

Looking into this.

@glenn-jocher
Copy link
Member

@glenn-jocher I'm getting another error now:

 File "train.py", line 342, in train
    wandb.log({tag: x})  # W&B
 raise wandb.Error("You must call wandb.init() before {}()".format(name))
wandb.errors.error.Error: You must call wandb.init() before wandb.log()
Internal process exited

Looking into this.

Ah I see. This makes sense actually, as I placed .init() in an if opt.resume statement, so it will only initialize if resuming. I need to take it back out. I'll do that.

@AyushExel
Copy link
Contributor Author

@glenn-jocher I'm getting another error now:

 File "train.py", line 342, in train
    wandb.log({tag: x})  # W&B
 raise wandb.Error("You must call wandb.init() before {}()".format(name))
wandb.errors.error.Error: You must call wandb.init() before wandb.log()
Internal process exited

Looking into this.

Ah I see. This makes sense actually, as I placed .init() in an if opt.resume statement, so it will only initialize if resuming. I need to take it back out. I'll do that.

Ahhh gotcha. Great catch. Thanks!

train.py Show resolved Hide resolved
train.py Show resolved Hide resolved
@glenn-jocher
Copy link
Member

All updates for this PR are complete. CI checks passing. Google colab example is working well. Will merge.

@glenn-jocher glenn-jocher added the enhancement New feature or request label Oct 31, 2020
@AyushExel
Copy link
Contributor Author

All updates for this PR are complete. CI checks passing. Google colab example is working well. Will merge.

Great!

@glenn-jocher glenn-jocher changed the title Weights & Biases (W&B) Logging Feature Addition Weights & Biases (W&B) Feature Addition Oct 31, 2020
@glenn-jocher glenn-jocher merged commit ca290dc into ultralytics:master Oct 31, 2020
@glenn-jocher
Copy link
Member

About Weights & Biases

Think of W&B like GitHub for machine learning models — save everything you need to debug, compare and reproduce your models — architecture, hyperparameters, weights, model predictions, GPU usage, git commits, and even datasets — with a few lines of code.

W&B lightweight integrations work with any Python script, and all you need to do is sign up for a free W&B account to start tracking and visualizing your models.

Used by the likes of OpenAI, Lyft, Github and researchers at top machine learning labs across the world, W&B is part of the new standard of best practices for machine learning.

How W&B can help you optimize your machine learning workflows:

W&B is free for individuals, academics and open source projects.

Untitled

YOLOv5 with W&B

Here's an in depth look at how the integration works: How are your yolov5 models doing?

When training with wandb installed, you get a an interactive bounding box debugging panel as shown here:

4d482f8f

burglarhobbit pushed a commit to burglarhobbit/yolov5 that referenced this pull request Jan 1, 2021
* Add wandb metric logging and bounding box debugging

* Improve formatting, readability

* Remove mutliple path for init, improve formatting

* Add wandb params

* Remove typecasting in bbox coordinates and reformat

* Cleanup

* add wandb to requirements.txt

* minor updates to test.py

* general reorg

* reduce --log-imgs to 10

* clean wandb import

* reverse wandb import assert

* add except AssertionError to try import

* move wandb init to all global ranks

* replace print() with logger.info()

* replace print() with logger.info()

* move wandb.init() bug fix

* project PosixPath to basename bug fix

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
KMint1819 pushed a commit to KMint1819/yolov5 that referenced this pull request May 12, 2021
* Add wandb metric logging and bounding box debugging

* Improve formatting, readability

* Remove mutliple path for init, improve formatting

* Add wandb params

* Remove typecasting in bbox coordinates and reformat

* Cleanup

* add wandb to requirements.txt

* minor updates to test.py

* general reorg

* reduce --log-imgs to 10

* clean wandb import

* reverse wandb import assert

* add except AssertionError to try import

* move wandb init to all global ranks

* replace print() with logger.info()

* replace print() with logger.info()

* move wandb.init() bug fix

* project PosixPath to basename bug fix

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
* Add wandb metric logging and bounding box debugging

* Improve formatting, readability

* Remove mutliple path for init, improve formatting

* Add wandb params

* Remove typecasting in bbox coordinates and reformat

* Cleanup

* add wandb to requirements.txt

* minor updates to test.py

* general reorg

* reduce --log-imgs to 10

* clean wandb import

* reverse wandb import assert

* add except AssertionError to try import

* move wandb init to all global ranks

* replace print() with logger.info()

* replace print() with logger.info()

* move wandb.init() bug fix

* project PosixPath to basename bug fix

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants