From 850cf0adeecc7ef6aeb9218fede80ef975321ea8 Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Mon, 14 Jun 2021 16:31:04 +0000 Subject: [PATCH 1/3] supress wandb images size mismatch warning --- utils/wandb_logging/wandb_utils.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/utils/wandb_logging/wandb_utils.py b/utils/wandb_logging/wandb_utils.py index 9975af63d02c..33d34fed0d86 100644 --- a/utils/wandb_logging/wandb_utils.py +++ b/utils/wandb_logging/wandb_utils.py @@ -2,6 +2,9 @@ import json import sys from pathlib import Path +import logging +from contextlib import contextmanager + import torch import yaml @@ -272,7 +275,7 @@ def create_dataset_table(self, dataset, class_to_id, name='dataset'): "box_caption": "%s" % (class_to_id[cls])}) img_classes[cls] = class_to_id[cls] boxes = {"ground_truth": {"box_data": box_data, "class_labels": class_to_id}} # inference-space - table.add_data(si, wandb.Image(paths, classes=class_set, boxes=boxes), json.dumps(img_classes), + table.add_data(si, wandb.Image(paths, classes=class_set, boxes=boxes), list(img_classes.values()), Path(paths).name) artifact.add(table, name) return artifact @@ -306,8 +309,9 @@ def log(self, log_dict): def end_epoch(self, best_result=False): if self.wandb_run: - wandb.log(self.log_dict) - self.log_dict = {} + with all_logging_disabled(): + wandb.log(self.log_dict) + self.log_dict = {} if self.result_artifact: train_results = wandb.JoinedTable(self.val_table, self.result_table, "id") self.result_artifact.add(train_results, 'result') @@ -321,3 +325,23 @@ def finish_run(self): if self.log_dict: wandb.log(self.log_dict) wandb.run.finish() + + +@contextmanager +def all_logging_disabled(highest_level=logging.CRITICAL): + """ + source - https://gist.github.com/simon-weber/7853144 + A context manager that will prevent any logging messages + triggered during the body from being processed. + :param highest_level: the maximum logging level in use. + This would only need to be changed if a custom level greater than CRITICAL + is defined. + """ + previous_level = logging.root.manager.disable + + logging.disable(highest_level) + + try: + yield + finally: + logging.disable(previous_level) From 93d7289c17ca144c4a38d673eb73d80c31145a37 Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Mon, 14 Jun 2021 16:35:25 +0000 Subject: [PATCH 2/3] supress wandb images size mismatch warning --- utils/wandb_logging/wandb_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/wandb_logging/wandb_utils.py b/utils/wandb_logging/wandb_utils.py index 33d34fed0d86..0629f7b59c8a 100644 --- a/utils/wandb_logging/wandb_utils.py +++ b/utils/wandb_logging/wandb_utils.py @@ -323,7 +323,8 @@ def end_epoch(self, best_result=False): def finish_run(self): if self.wandb_run: if self.log_dict: - wandb.log(self.log_dict) + with all_logging_disabled(): + wandb.log(self.log_dict) wandb.run.finish() From 3e8bcc3dcfa7a634f30cde53cd432af3e05dce94 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 14 Jun 2021 18:48:49 +0200 Subject: [PATCH 3/3] PEP8 reformat and optimize imports --- utils/wandb_logging/wandb_utils.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/utils/wandb_logging/wandb_utils.py b/utils/wandb_logging/wandb_utils.py index 0629f7b59c8a..7652f964f2c0 100644 --- a/utils/wandb_logging/wandb_utils.py +++ b/utils/wandb_logging/wandb_utils.py @@ -1,19 +1,16 @@ """Utilities and tools for tracking runs with Weights & Biases.""" -import json -import sys -from pathlib import Path import logging +import sys from contextlib import contextmanager +from pathlib import Path - -import torch import yaml from tqdm import tqdm sys.path.append(str(Path(__file__).parent.parent.parent)) # add utils/ to path from utils.datasets import LoadImagesAndLabels from utils.datasets import img2label_paths -from utils.general import colorstr, xywh2xyxy, check_dataset, check_file +from utils.general import colorstr, check_dataset, check_file try: import wandb @@ -95,6 +92,7 @@ class WandbLogger(): For more on how this logger is used, see the Weights & Biases documentation: https://docs.wandb.com/guides/integrations/yolov5 """ + def __init__(self, opt, name, run_id, data_dict, job_type='Training'): # Pre-training routine -- self.job_type = job_type @@ -309,7 +307,7 @@ def log(self, log_dict): def end_epoch(self, best_result=False): if self.wandb_run: - with all_logging_disabled(): + with all_logging_disabled(): wandb.log(self.log_dict) self.log_dict = {} if self.result_artifact: @@ -323,25 +321,20 @@ def end_epoch(self, best_result=False): def finish_run(self): if self.wandb_run: if self.log_dict: - with all_logging_disabled(): + with all_logging_disabled(): wandb.log(self.log_dict) wandb.run.finish() @contextmanager def all_logging_disabled(highest_level=logging.CRITICAL): - """ - source - https://gist.github.com/simon-weber/7853144 - A context manager that will prevent any logging messages - triggered during the body from being processed. + """ source - https://gist.github.com/simon-weber/7853144 + A context manager that will prevent any logging messages triggered during the body from being processed. :param highest_level: the maximum logging level in use. - This would only need to be changed if a custom level greater than CRITICAL - is defined. + This would only need to be changed if a custom level greater than CRITICAL is defined. """ previous_level = logging.root.manager.disable - logging.disable(highest_level) - try: yield finally: