2021-08-15 03:17:51 +08:00
|
|
|
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
|
|
|
|
"""
|
|
|
|
Logging utils
|
|
|
|
"""
|
|
|
|
|
2021-10-14 07:17:15 +08:00
|
|
|
import os
|
2021-07-25 07:18:39 +08:00
|
|
|
import warnings
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
from pathlib import Path
|
2021-07-29 05:35:14 +08:00
|
|
|
|
2021-10-14 07:17:15 +08:00
|
|
|
import pkg_resources as pkg
|
2021-07-29 05:35:14 +08:00
|
|
|
import torch
|
2021-07-25 07:18:39 +08:00
|
|
|
from torch.utils.tensorboard import SummaryWriter
|
|
|
|
|
2022-08-21 09:47:37 +08:00
|
|
|
from utils.general import colorstr, cv2, threaded
|
2022-08-06 02:50:49 +08:00
|
|
|
from utils.loggers.clearml.clearml_utils import ClearmlLogger
|
2021-07-25 07:18:39 +08:00
|
|
|
from utils.loggers.wandb.wandb_utils import WandbLogger
|
2022-08-21 09:47:37 +08:00
|
|
|
from utils.plots import plot_images, plot_labels, plot_results
|
2021-07-25 07:18:39 +08:00
|
|
|
from utils.torch_utils import de_parallel
|
|
|
|
|
2022-08-06 02:50:49 +08:00
|
|
|
LOGGERS = ('csv', 'tb', 'wandb', 'clearml') # *.csv, TensorBoard, Weights & Biases, ClearML
|
2021-10-14 07:17:15 +08:00
|
|
|
RANK = int(os.getenv('RANK', -1))
|
2021-07-25 07:18:39 +08:00
|
|
|
|
|
|
|
try:
|
|
|
|
import wandb
|
|
|
|
|
|
|
|
assert hasattr(wandb, '__version__') # verify package import not local dir
|
2022-05-15 22:38:26 +08:00
|
|
|
if pkg.parse_version(wandb.__version__) >= pkg.parse_version('0.12.2') and RANK in {0, -1}:
|
2021-12-01 22:38:02 +08:00
|
|
|
try:
|
|
|
|
wandb_login_success = wandb.login(timeout=30)
|
|
|
|
except wandb.errors.UsageError: # known non-TTY terminal issue
|
|
|
|
wandb_login_success = False
|
2021-10-14 07:17:15 +08:00
|
|
|
if not wandb_login_success:
|
|
|
|
wandb = None
|
2021-07-25 07:18:39 +08:00
|
|
|
except (ImportError, AssertionError):
|
|
|
|
wandb = None
|
|
|
|
|
2022-08-06 02:50:49 +08:00
|
|
|
try:
|
|
|
|
import clearml
|
|
|
|
|
|
|
|
assert hasattr(clearml, '__version__') # verify package import not local dir
|
|
|
|
except (ImportError, AssertionError):
|
|
|
|
clearml = None
|
|
|
|
|
2021-07-25 07:18:39 +08:00
|
|
|
|
|
|
|
class Loggers():
|
|
|
|
# YOLOv5 Loggers class
|
2021-07-28 23:40:08 +08:00
|
|
|
def __init__(self, save_dir=None, weights=None, opt=None, hyp=None, logger=None, include=LOGGERS):
|
2021-07-25 07:18:39 +08:00
|
|
|
self.save_dir = save_dir
|
|
|
|
self.weights = weights
|
|
|
|
self.opt = opt
|
|
|
|
self.hyp = hyp
|
|
|
|
self.logger = logger # for printing results to console
|
|
|
|
self.include = include
|
2022-03-31 22:52:34 +08:00
|
|
|
self.keys = [
|
|
|
|
'train/box_loss',
|
|
|
|
'train/obj_loss',
|
|
|
|
'train/cls_loss', # train loss
|
|
|
|
'metrics/precision',
|
|
|
|
'metrics/recall',
|
|
|
|
'metrics/mAP_0.5',
|
|
|
|
'metrics/mAP_0.5:0.95', # metrics
|
|
|
|
'val/box_loss',
|
|
|
|
'val/obj_loss',
|
|
|
|
'val/cls_loss', # val loss
|
|
|
|
'x/lr0',
|
|
|
|
'x/lr1',
|
|
|
|
'x/lr2'] # params
|
2022-03-21 01:17:04 +08:00
|
|
|
self.best_keys = ['best/epoch', 'best/precision', 'best/recall', 'best/mAP_0.5', 'best/mAP_0.5:0.95']
|
2021-07-25 07:18:39 +08:00
|
|
|
for k in LOGGERS:
|
|
|
|
setattr(self, k, None) # init empty logger dictionary
|
2021-07-26 01:06:37 +08:00
|
|
|
self.csv = True # always log to csv
|
2021-07-25 07:18:39 +08:00
|
|
|
|
2022-08-06 02:50:49 +08:00
|
|
|
# Messages
|
2021-07-28 23:40:08 +08:00
|
|
|
if not wandb:
|
2021-07-25 07:18:39 +08:00
|
|
|
prefix = colorstr('Weights & Biases: ')
|
2022-08-06 02:50:49 +08:00
|
|
|
s = f"{prefix}run 'pip install wandb' to automatically track and visualize YOLOv5 🚀 runs in Weights & Biases"
|
2022-08-06 18:30:08 +08:00
|
|
|
self.logger.info(s)
|
2022-08-06 02:50:49 +08:00
|
|
|
if not clearml:
|
|
|
|
prefix = colorstr('ClearML: ')
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
s = f"{prefix}run 'pip install clearml' to automatically track, visualize and remotely train YOLOv5 🚀 in ClearML"
|
2022-08-06 18:30:08 +08:00
|
|
|
self.logger.info(s)
|
2021-07-25 07:18:39 +08:00
|
|
|
|
|
|
|
# TensorBoard
|
|
|
|
s = self.save_dir
|
|
|
|
if 'tb' in self.include and not self.opt.evolve:
|
|
|
|
prefix = colorstr('TensorBoard: ')
|
|
|
|
self.logger.info(f"{prefix}Start with 'tensorboard --logdir {s.parent}', view at http://localhost:6006/")
|
|
|
|
self.tb = SummaryWriter(str(s))
|
|
|
|
|
|
|
|
# W&B
|
2021-07-29 05:25:15 +08:00
|
|
|
if wandb and 'wandb' in self.include:
|
|
|
|
wandb_artifact_resume = isinstance(self.opt.resume, str) and self.opt.resume.startswith('wandb-artifact://')
|
|
|
|
run_id = torch.load(self.weights).get('wandb_id') if self.opt.resume and not wandb_artifact_resume else None
|
2021-07-25 07:18:39 +08:00
|
|
|
self.opt.hyp = self.hyp # add hyperparameters
|
2021-07-28 23:40:08 +08:00
|
|
|
self.wandb = WandbLogger(self.opt, run_id)
|
2022-04-12 17:46:56 +08:00
|
|
|
# temp warn. because nested artifacts not supported after 0.12.10
|
|
|
|
if pkg.parse_version(wandb.__version__) >= pkg.parse_version('0.12.11'):
|
2022-08-06 02:50:49 +08:00
|
|
|
s = "YOLOv5 temporarily requires wandb version 0.12.10 or below. Some features may not work as expected."
|
|
|
|
self.logger.warning(s)
|
2021-07-29 05:25:15 +08:00
|
|
|
else:
|
2021-07-25 07:18:39 +08:00
|
|
|
self.wandb = None
|
|
|
|
|
2022-08-06 02:50:49 +08:00
|
|
|
# ClearML
|
|
|
|
if clearml and 'clearml' in self.include:
|
|
|
|
self.clearml = ClearmlLogger(self.opt, self.hyp)
|
|
|
|
else:
|
|
|
|
self.clearml = None
|
|
|
|
|
2022-04-06 23:23:34 +08:00
|
|
|
def on_train_start(self):
|
|
|
|
# Callback runs on train start
|
|
|
|
pass
|
|
|
|
|
2022-08-21 09:47:37 +08:00
|
|
|
def on_pretrain_routine_end(self, labels, names, plots):
|
2021-08-01 06:18:07 +08:00
|
|
|
# Callback runs on pre-train routine end
|
2022-08-21 09:47:37 +08:00
|
|
|
if plots:
|
|
|
|
plot_labels(labels, names, self.save_dir)
|
2021-08-01 06:18:07 +08:00
|
|
|
paths = self.save_dir.glob('*labels*.jpg') # training labels
|
|
|
|
if self.wandb:
|
|
|
|
self.wandb.log({"Labels": [wandb.Image(str(x), caption=x.name) for x in paths]})
|
2022-08-21 09:47:37 +08:00
|
|
|
# if self.clearml:
|
|
|
|
# pass # ClearML saves these images automatically using hooks
|
2021-07-25 07:18:39 +08:00
|
|
|
|
2022-04-23 06:04:08 +08:00
|
|
|
def on_train_batch_end(self, ni, model, imgs, targets, paths, plots):
|
2021-07-25 07:18:39 +08:00
|
|
|
# Callback runs on train batch end
|
2022-08-06 02:50:49 +08:00
|
|
|
# ni: number integrated batches (since train start)
|
2021-07-26 01:06:37 +08:00
|
|
|
if plots:
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
if ni == 0 and not self.opt.sync_bn and self.tb:
|
|
|
|
log_tensorboard_graph(self.tb, model, imgsz=list(imgs.shape[2:4]))
|
2021-07-26 01:06:37 +08:00
|
|
|
if ni < 3:
|
|
|
|
f = self.save_dir / f'train_batch{ni}.jpg' # filename
|
2022-05-14 22:12:08 +08:00
|
|
|
plot_images(imgs, targets, paths, f)
|
2022-08-06 02:50:49 +08:00
|
|
|
if (self.wandb or self.clearml) and ni == 10:
|
2021-07-26 01:06:37 +08:00
|
|
|
files = sorted(self.save_dir.glob('train*.jpg'))
|
2022-08-06 02:50:49 +08:00
|
|
|
if self.wandb:
|
|
|
|
self.wandb.log({'Mosaics': [wandb.Image(str(f), caption=f.name) for f in files if f.exists()]})
|
|
|
|
if self.clearml:
|
|
|
|
self.clearml.log_debug_samples(files, title='Mosaics')
|
2021-07-25 07:18:39 +08:00
|
|
|
|
|
|
|
def on_train_epoch_end(self, epoch):
|
|
|
|
# Callback runs on train epoch end
|
|
|
|
if self.wandb:
|
|
|
|
self.wandb.current_epoch = epoch + 1
|
|
|
|
|
2021-08-01 06:18:07 +08:00
|
|
|
def on_val_image_end(self, pred, predn, path, names, im):
|
|
|
|
# Callback runs on val image end
|
2021-07-25 07:18:39 +08:00
|
|
|
if self.wandb:
|
|
|
|
self.wandb.val_one_image(pred, predn, path, names, im)
|
2022-08-06 02:50:49 +08:00
|
|
|
if self.clearml:
|
|
|
|
self.clearml.log_image_with_boxes(path, pred, names, im)
|
2021-07-25 07:18:39 +08:00
|
|
|
|
|
|
|
def on_val_end(self):
|
|
|
|
# Callback runs on val end
|
2022-08-06 02:50:49 +08:00
|
|
|
if self.wandb or self.clearml:
|
2021-07-25 07:18:39 +08:00
|
|
|
files = sorted(self.save_dir.glob('val*.jpg'))
|
2022-08-06 02:50:49 +08:00
|
|
|
if self.wandb:
|
|
|
|
self.wandb.log({"Validation": [wandb.Image(str(f), caption=f.name) for f in files]})
|
|
|
|
if self.clearml:
|
|
|
|
self.clearml.log_debug_samples(files, title='Validation')
|
2021-07-25 07:18:39 +08:00
|
|
|
|
2021-08-04 23:13:38 +08:00
|
|
|
def on_fit_epoch_end(self, vals, epoch, best_fitness, fi):
|
2021-08-01 06:18:07 +08:00
|
|
|
# Callback runs at the end of each fit (train+val) epoch
|
2022-05-14 22:12:08 +08:00
|
|
|
x = dict(zip(self.keys, vals))
|
2021-07-26 01:06:37 +08:00
|
|
|
if self.csv:
|
|
|
|
file = self.save_dir / 'results.csv'
|
|
|
|
n = len(x) + 1 # number of cols
|
2021-08-01 06:18:07 +08:00
|
|
|
s = '' if file.exists() else (('%20s,' * n % tuple(['epoch'] + self.keys)).rstrip(',') + '\n') # add header
|
2021-07-26 01:06:37 +08:00
|
|
|
with open(file, 'a') as f:
|
|
|
|
f.write(s + ('%20.5g,' * n % tuple([epoch] + vals)).rstrip(',') + '\n')
|
|
|
|
|
2021-07-25 07:18:39 +08:00
|
|
|
if self.tb:
|
2021-07-26 01:06:37 +08:00
|
|
|
for k, v in x.items():
|
2021-08-01 06:18:07 +08:00
|
|
|
self.tb.add_scalar(k, v, epoch)
|
2022-08-06 02:50:49 +08:00
|
|
|
elif self.clearml: # log to ClearML if TensorBoard not used
|
|
|
|
for k, v in x.items():
|
|
|
|
title, series = k.split('/')
|
|
|
|
self.clearml.task.get_logger().report_scalar(title, series, v, epoch)
|
2021-07-26 01:06:37 +08:00
|
|
|
|
2021-07-25 07:18:39 +08:00
|
|
|
if self.wandb:
|
2021-12-31 05:47:53 +08:00
|
|
|
if best_fitness == fi:
|
|
|
|
best_results = [epoch] + vals[3:7]
|
|
|
|
for i, name in enumerate(self.best_keys):
|
|
|
|
self.wandb.wandb_run.summary[name] = best_results[i] # log best results in the summary
|
2021-07-26 01:06:37 +08:00
|
|
|
self.wandb.log(x)
|
2021-07-25 07:18:39 +08:00
|
|
|
self.wandb.end_epoch(best_result=best_fitness == fi)
|
|
|
|
|
2022-08-06 02:50:49 +08:00
|
|
|
if self.clearml:
|
|
|
|
self.clearml.current_epoch_logged_images = set() # reset epoch image limit
|
|
|
|
self.clearml.current_epoch += 1
|
|
|
|
|
2021-07-25 07:18:39 +08:00
|
|
|
def on_model_save(self, last, epoch, final_epoch, best_fitness, fi):
|
|
|
|
# Callback runs on model save event
|
2022-08-21 08:00:35 +08:00
|
|
|
if (epoch + 1) % self.opt.save_period == 0 and not final_epoch and self.opt.save_period != -1:
|
|
|
|
if self.wandb:
|
2021-07-25 07:18:39 +08:00
|
|
|
self.wandb.log_model(last.parent, self.opt, epoch, fi, best_model=best_fitness == fi)
|
2022-08-21 08:00:35 +08:00
|
|
|
if self.clearml:
|
2022-08-06 02:50:49 +08:00
|
|
|
self.clearml.task.update_output_model(model_path=str(last),
|
|
|
|
model_name='Latest Model',
|
|
|
|
auto_delete_file=False)
|
|
|
|
|
2021-10-18 20:28:22 +08:00
|
|
|
def on_train_end(self, last, best, plots, epoch, results):
|
2022-08-21 08:00:35 +08:00
|
|
|
# Callback runs on training end, i.e. saving best model
|
2021-07-26 01:06:37 +08:00
|
|
|
if plots:
|
2021-08-04 23:13:38 +08:00
|
|
|
plot_results(file=self.save_dir / 'results.csv') # save results.png
|
2021-10-29 00:35:01 +08:00
|
|
|
files = ['results.png', 'confusion_matrix.png', *(f'{x}_curve.png' for x in ('F1', 'PR', 'P', 'R'))]
|
2021-07-25 07:18:39 +08:00
|
|
|
files = [(self.save_dir / f) for f in files if (self.save_dir / f).exists()] # filter
|
2022-05-06 12:25:13 +08:00
|
|
|
self.logger.info(f"Results saved to {colorstr('bold', self.save_dir)}")
|
2021-08-01 06:18:07 +08:00
|
|
|
|
2022-08-06 02:50:49 +08:00
|
|
|
if self.tb and not self.clearml: # These images are already captured by ClearML by now, we don't want doubles
|
2021-08-01 06:18:07 +08:00
|
|
|
for f in files:
|
2021-08-30 19:01:41 +08:00
|
|
|
self.tb.add_image(f.stem, cv2.imread(str(f))[..., ::-1], epoch, dataformats='HWC')
|
2021-08-01 06:18:07 +08:00
|
|
|
|
2021-07-25 07:18:39 +08:00
|
|
|
if self.wandb:
|
2022-05-14 22:12:08 +08:00
|
|
|
self.wandb.log(dict(zip(self.keys[3:10], results)))
|
2021-08-01 18:06:53 +08:00
|
|
|
self.wandb.log({"Results": [wandb.Image(str(f), caption=f.name) for f in files]})
|
|
|
|
# Calling wandb.log. TODO: Refactor this into WandbLogger.log_model
|
2021-08-30 23:07:20 +08:00
|
|
|
if not self.opt.evolve:
|
2022-03-31 22:52:34 +08:00
|
|
|
wandb.log_artifact(str(best if best.exists() else last),
|
|
|
|
type='model',
|
2022-05-15 22:38:26 +08:00
|
|
|
name=f'run_{self.wandb.wandb_run.id}_model',
|
2021-08-30 23:07:20 +08:00
|
|
|
aliases=['latest', 'best', 'stripped'])
|
2022-01-21 07:22:47 +08:00
|
|
|
self.wandb.finish_run()
|
2021-12-23 21:23:50 +08:00
|
|
|
|
2022-08-21 08:00:35 +08:00
|
|
|
if self.clearml and not self.opt.evolve:
|
|
|
|
self.clearml.task.update_output_model(model_path=str(best if best.exists() else last), name='Best Model')
|
2022-08-06 02:50:49 +08:00
|
|
|
|
2022-08-21 08:00:35 +08:00
|
|
|
def on_params_update(self, params: dict):
|
2021-12-23 21:23:50 +08:00
|
|
|
# Update hyperparams or configs of the experiment
|
|
|
|
if self.wandb:
|
|
|
|
self.wandb.wandb_run.config.update(params, allow_val_change=True)
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
class GenericLogger:
|
|
|
|
"""
|
|
|
|
YOLOv5 General purpose logger for non-task specific logging
|
|
|
|
Usage: from utils.loggers import GenericLogger; logger = GenericLogger(...)
|
|
|
|
Arguments
|
|
|
|
opt: Run arguments
|
|
|
|
console_logger: Console logger
|
|
|
|
include: loggers to include
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, opt, console_logger, include=('tb', 'wandb')):
|
|
|
|
# init default loggers
|
|
|
|
self.save_dir = opt.save_dir
|
|
|
|
self.include = include
|
|
|
|
self.console_logger = console_logger
|
|
|
|
if 'tb' in self.include:
|
|
|
|
prefix = colorstr('TensorBoard: ')
|
|
|
|
self.console_logger.info(
|
|
|
|
f"{prefix}Start with 'tensorboard --logdir {self.save_dir.parent}', view at http://localhost:6006/")
|
|
|
|
self.tb = SummaryWriter(str(self.save_dir))
|
|
|
|
|
|
|
|
if wandb and 'wandb' in self.include:
|
|
|
|
self.wandb = wandb.init(project="YOLOv5-Classifier" if opt.project == "runs/train" else opt.project,
|
|
|
|
name=None if opt.name == "exp" else opt.name,
|
|
|
|
config=opt)
|
|
|
|
else:
|
|
|
|
self.wandb = None
|
|
|
|
|
|
|
|
def log_metrics(self, metrics_dict, epoch):
|
|
|
|
# Log metrics dictionary to all loggers
|
|
|
|
if self.tb:
|
|
|
|
for k, v in metrics_dict.items():
|
|
|
|
self.tb.add_scalar(k, v, epoch)
|
|
|
|
|
|
|
|
if self.wandb:
|
|
|
|
self.wandb.log(metrics_dict, step=epoch)
|
|
|
|
|
|
|
|
def log_images(self, files, name='Images', epoch=0):
|
|
|
|
# Log images to all loggers
|
|
|
|
files = [Path(f) for f in (files if isinstance(files, (tuple, list)) else [files])] # to Path
|
|
|
|
files = [f for f in files if f.exists()] # filter by exists
|
|
|
|
|
|
|
|
if self.tb:
|
|
|
|
for f in files:
|
|
|
|
self.tb.add_image(f.stem, cv2.imread(str(f))[..., ::-1], epoch, dataformats='HWC')
|
|
|
|
|
|
|
|
if self.wandb:
|
|
|
|
self.wandb.log({name: [wandb.Image(str(f), caption=f.name) for f in files]}, step=epoch)
|
|
|
|
|
|
|
|
def log_graph(self, model, imgsz=(640, 640)):
|
|
|
|
# Log model graph to all loggers
|
|
|
|
if self.tb:
|
|
|
|
log_tensorboard_graph(self.tb, model, imgsz)
|
|
|
|
|
|
|
|
def log_model(self, model_path, epoch=0, metadata={}):
|
|
|
|
# Log model to all loggers
|
|
|
|
if self.wandb:
|
|
|
|
art = wandb.Artifact(name=f"run_{wandb.run.id}_model", type="model", metadata=metadata)
|
|
|
|
art.add_file(str(model_path))
|
|
|
|
wandb.log_artifact(art)
|
|
|
|
|
|
|
|
|
|
|
|
def log_tensorboard_graph(tb, model, imgsz=(640, 640)):
|
|
|
|
# Log model graph to TensorBoard
|
|
|
|
try:
|
|
|
|
p = next(model.parameters()) # for device, type
|
|
|
|
imgsz = (imgsz, imgsz) if isinstance(imgsz, int) else imgsz # expand
|
2022-08-19 02:12:33 +08:00
|
|
|
im = torch.empty((1, 3, *imgsz)).to(p.device).type_as(p) # input image
|
New YOLOv5 Classification Models (#8956)
* Update
* Logger step fix: Increment step with epochs (#8654)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Allow logging models from GenericLogger (#8676)
* enhance
* revert
* allow training from scratch
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update --img argument from train.py
single line
* fix image size from 640 to 128
* suport custom dataloader and augmentation
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* format
* Update dataloaders.py
* Single line return, single line comment, remove unused argument
* address PR comments
* fix spelling
* don't augment eval set
* use fstring
* update augmentations.py
* new maning convention for transforms
* reverse if statement, inline ops
* reverse if statement, inline ops
* updates
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update dataloaders
* Remove additional if statement
* Remove is_train as redundant
* Cleanup
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Cleanup2
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update augmentations.py
* fix: imshow clip warning
* update
* Revert ToTensorV2 removal
* Update classifier.py
* Update normalize values, revert uint8
* normalize image using cv2
* remove dedundant comment
* Update classifier.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* replace print with logger
* commit steps
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* support final model logging
* update
* update
* update
* update
* remove curses
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update classifier.py
* Update __init__.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
* Update
* Update
* Update
* Update
* Update dataset download
* Update dataset download
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Pass imgsz to classify_transforms()
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Cos scheduler
* Cos scheduler
* Remove unused args
* Update
* Add seed
* Add seed
* Update
* Update
* Add run(), main()
* Merge master
* Merge master
* Update
* Update
* Update
* Update
* Update
* Update
* Update
* Create YOLOv5 BaseModel class (#8829)
* Create BaseModel
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fix
* Hub load device fix
* Update
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add experiment
* Merge master
* Attach names
* weight decay = 1e-4
* weight decay = 5e-5
* update smart_optimizer console printout
* fashion-mnist fix
* Merge master
* Update Table
* Update Table
* Remove destroy process group
* add kwargs to forward()
* fuse fix for resnet50
* nc, names fix for resnet50
* nc, names fix for resnet50
* ONNX CPU inference fix
* revert
* cuda
* if augment or visualize
* if augment or visualize
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* New smart_inference_mode()
* Update README
* Refactor into /classify dir
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* reset defaults
* reset defaults
* fix gpu predict
* warmup
* ema half fix
* spacing
* remove data
* remove cache
* remove denormalize
* save run settings
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* verbose false on initial plots
* new save_yaml() function
* Update ci-testing.yml
* Path(data) CI fix
* Separate classification CI
* fix val
* fix val
* fix val
* smartCrossEntropyLoss
* skip validation on hub load
* autodownload with working dir root
* str(data)
* Dataset usage example
* im_show normalize
* im_show normalize
* add imagenet simple names to multibackend
* Add validation speeds
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* 24-space names
* Update bash scripts
* Update permissions
* Add bash script arguments
* remove verbose
* TRT data fix
* names generator fix
* optimize if names
* update usage
* Add local loading
* Verbose=False
* update names printing
* Add Usage examples
* Add Usage examples
* Add Usage examples
* Add Usage examples
* named_children
* reshape_classifier_outputs
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* update
* update
* fix CI
* fix incorrect class substitution
* fix incorrect class substitution
* remove denormalize
* ravel fix
* cleanup
* update opt file printing
* update opt file printing
* update defaults
* add opt to checkpoint
* Add warning
* Add comment
* plot half bug fix
* Use NotImplementedError
* fix export shape report
* Fix TRT load
* cleanup CI
* profile comment
* CI fix
* Add cls models
* avoid inplace error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix usage examples
* Update README
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
* Update README
Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-17 17:59:01 +08:00
|
|
|
with warnings.catch_warnings():
|
|
|
|
warnings.simplefilter('ignore') # suppress jit trace warning
|
|
|
|
tb.add_graph(torch.jit.trace(de_parallel(model), im, strict=False), [])
|
|
|
|
except Exception:
|
|
|
|
print('WARNING: TensorBoard graph visualization failure')
|