Skip to content

Commit

Permalink
Comet updates (#11818)
Browse files Browse the repository at this point in the history
* update colab link

* fix path check for datasets

* apply yapf

* run precommit hooks

* [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>
  • Loading branch information
DN6 and pre-commit-ci[bot] committed Jul 6, 2023
1 parent 459dd49 commit 485da42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion utils/loggers/comet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Check out an example of a [completed run here](https://www.comet.com/examples/co

Or better yet, try it out yourself in this Colab Notebook

[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1RG0WOQyxlDlo5Km8GogJpIEJlg_5lyYO?usp=sharing)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/comet-ml/comet-examples/blob/master/integrations/model-training/yolov5/notebooks/Comet_and_YOLOv5.ipynb)

# Log automatically

Expand Down
28 changes: 19 additions & 9 deletions utils/loggers/comet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
COMET_UPLOAD_DATASET = os.getenv('COMET_UPLOAD_DATASET', 'false').lower() == 'true'

# Evaluation Settings
COMET_LOG_CONFUSION_MATRIX = os.getenv('COMET_LOG_CONFUSION_MATRIX', 'true').lower() == 'true'
COMET_LOG_CONFUSION_MATRIX = (os.getenv('COMET_LOG_CONFUSION_MATRIX', 'true').lower() == 'true')
COMET_LOG_PREDICTIONS = os.getenv('COMET_LOG_PREDICTIONS', 'true').lower() == 'true'
COMET_MAX_IMAGE_UPLOADS = int(os.getenv('COMET_MAX_IMAGE_UPLOADS', 100))

Expand All @@ -51,10 +51,10 @@
IOU_THRES = float(os.getenv('IOU_THRES', 0.6))

# Batch Logging Settings
COMET_LOG_BATCH_METRICS = os.getenv('COMET_LOG_BATCH_METRICS', 'false').lower() == 'true'
COMET_LOG_BATCH_METRICS = (os.getenv('COMET_LOG_BATCH_METRICS', 'false').lower() == 'true')
COMET_BATCH_LOGGING_INTERVAL = os.getenv('COMET_BATCH_LOGGING_INTERVAL', 1)
COMET_PREDICTION_LOGGING_INTERVAL = os.getenv('COMET_PREDICTION_LOGGING_INTERVAL', 1)
COMET_LOG_PER_CLASS_METRICS = os.getenv('COMET_LOG_PER_CLASS_METRICS', 'false').lower() == 'true'
COMET_LOG_PER_CLASS_METRICS = (os.getenv('COMET_LOG_PER_CLASS_METRICS', 'false').lower() == 'true')

RANK = int(os.getenv('RANK', -1))

Expand Down Expand Up @@ -137,7 +137,7 @@ def __init__(self, opt, hyp, run_id=None, job_type='Training', **experiment_kwar

self.comet_log_predictions = COMET_LOG_PREDICTIONS
if self.opt.bbox_interval == -1:
self.comet_log_prediction_interval = 1 if self.opt.epochs < 10 else self.opt.epochs // 10
self.comet_log_prediction_interval = (1 if self.opt.epochs < 10 else self.opt.epochs // 10)
else:
self.comet_log_prediction_interval = self.opt.bbox_interval

Expand Down Expand Up @@ -232,7 +232,8 @@ def check_dataset(self, data_file):
with open(data_file) as f:
data_config = yaml.safe_load(f)

if data_config['path'].startswith(COMET_PREFIX):
path = data_config.get('path')
if path and path.startswith(COMET_PREFIX):
path = data_config['path'].replace(COMET_PREFIX, '')
data_dict = self.download_dataset_artifact(path)

Expand Down Expand Up @@ -313,8 +314,16 @@ def add_assets_to_artifact(self, artifact, path, asset_path, split):
image_logical_path, label_logical_path = map(lambda x: os.path.relpath(x, path), [image_file, label_file])

try:
artifact.add(image_file, logical_path=image_logical_path, metadata={'split': split})
artifact.add(label_file, logical_path=label_logical_path, metadata={'split': split})
artifact.add(
image_file,
logical_path=image_logical_path,
metadata={'split': split},
)
artifact.add(
label_file,
logical_path=label_logical_path,
metadata={'split': split},
)
except ValueError as e:
logger.error('COMET ERROR: Error adding file to Artifact. Skipping file.')
logger.error(f'COMET ERROR: {e}')
Expand Down Expand Up @@ -476,8 +485,9 @@ def on_val_end(self, nt, tp, fp, p, r, f1, ap, ap50, ap_class, confusion_matrix)
'f1': f1[i],
'true_positives': tp[i],
'false_positives': fp[i],
'support': nt[c]},
prefix=class_name)
'support': nt[c], },
prefix=class_name,
)

if self.comet_log_confusion_matrix:
epoch = self.experiment.curr_epoch
Expand Down

0 comments on commit 485da42

Please sign in to comment.