Suppress wandb images size mismatch warning (#3611)
Browse files* supress wandb images size mismatch warning
* supress wandb images size mismatch warning
* PEP8 reformat and optimize imports
Co-authored-by: Glenn Jocher <[email protected]>
utils/wandb_logging/wandb_utils.py
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
"""Utilities and tools for tracking runs with Weights & Biases."""
|
2 |
-
import
|
3 |
import sys
|
|
|
4 |
from pathlib import Path
|
5 |
|
6 |
-
import torch
|
7 |
import yaml
|
8 |
from tqdm import tqdm
|
9 |
|
10 |
sys.path.append(str(Path(__file__).parent.parent.parent)) # add utils/ to path
|
11 |
from utils.datasets import LoadImagesAndLabels
|
12 |
from utils.datasets import img2label_paths
|
13 |
-
from utils.general import colorstr,
|
14 |
|
15 |
try:
|
16 |
import wandb
|
@@ -92,6 +92,7 @@ class WandbLogger():
|
|
92 |
For more on how this logger is used, see the Weights & Biases documentation:
|
93 |
https://docs.wandb.com/guides/integrations/yolov5
|
94 |
"""
|
|
|
95 |
def __init__(self, opt, name, run_id, data_dict, job_type='Training'):
|
96 |
# Pre-training routine --
|
97 |
self.job_type = job_type
|
@@ -272,7 +273,7 @@ class WandbLogger():
|
|
272 |
"box_caption": "%s" % (class_to_id[cls])})
|
273 |
img_classes[cls] = class_to_id[cls]
|
274 |
boxes = {"ground_truth": {"box_data": box_data, "class_labels": class_to_id}} # inference-space
|
275 |
-
table.add_data(si, wandb.Image(paths, classes=class_set, boxes=boxes),
|
276 |
Path(paths).name)
|
277 |
artifact.add(table, name)
|
278 |
return artifact
|
@@ -306,8 +307,9 @@ class WandbLogger():
|
|
306 |
|
307 |
def end_epoch(self, best_result=False):
|
308 |
if self.wandb_run:
|
309 |
-
|
310 |
-
|
|
|
311 |
if self.result_artifact:
|
312 |
train_results = wandb.JoinedTable(self.val_table, self.result_table, "id")
|
313 |
self.result_artifact.add(train_results, 'result')
|
@@ -319,5 +321,21 @@ class WandbLogger():
|
|
319 |
def finish_run(self):
|
320 |
if self.wandb_run:
|
321 |
if self.log_dict:
|
322 |
-
|
|
|
323 |
wandb.run.finish()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
"""Utilities and tools for tracking runs with Weights & Biases."""
|
2 |
+
import logging
|
3 |
import sys
|
4 |
+
from contextlib import contextmanager
|
5 |
from pathlib import Path
|
6 |
|
|
|
7 |
import yaml
|
8 |
from tqdm import tqdm
|
9 |
|
10 |
sys.path.append(str(Path(__file__).parent.parent.parent)) # add utils/ to path
|
11 |
from utils.datasets import LoadImagesAndLabels
|
12 |
from utils.datasets import img2label_paths
|
13 |
+
from utils.general import colorstr, check_dataset, check_file
|
14 |
|
15 |
try:
|
16 |
import wandb
|
|
|
92 |
For more on how this logger is used, see the Weights & Biases documentation:
|
93 |
https://docs.wandb.com/guides/integrations/yolov5
|
94 |
"""
|
95 |
+
|
96 |
def __init__(self, opt, name, run_id, data_dict, job_type='Training'):
|
97 |
# Pre-training routine --
|
98 |
self.job_type = job_type
|
|
|
273 |
"box_caption": "%s" % (class_to_id[cls])})
|
274 |
img_classes[cls] = class_to_id[cls]
|
275 |
boxes = {"ground_truth": {"box_data": box_data, "class_labels": class_to_id}} # inference-space
|
276 |
+
table.add_data(si, wandb.Image(paths, classes=class_set, boxes=boxes), list(img_classes.values()),
|
277 |
Path(paths).name)
|
278 |
artifact.add(table, name)
|
279 |
return artifact
|
|
|
307 |
|
308 |
def end_epoch(self, best_result=False):
|
309 |
if self.wandb_run:
|
310 |
+
with all_logging_disabled():
|
311 |
+
wandb.log(self.log_dict)
|
312 |
+
self.log_dict = {}
|
313 |
if self.result_artifact:
|
314 |
train_results = wandb.JoinedTable(self.val_table, self.result_table, "id")
|
315 |
self.result_artifact.add(train_results, 'result')
|
|
|
321 |
def finish_run(self):
|
322 |
if self.wandb_run:
|
323 |
if self.log_dict:
|
324 |
+
with all_logging_disabled():
|
325 |
+
wandb.log(self.log_dict)
|
326 |
wandb.run.finish()
|
327 |
+
|
328 |
+
|
329 |
+
@contextmanager
|
330 |
+
def all_logging_disabled(highest_level=logging.CRITICAL):
|
331 |
+
""" source - https://gist.github.com/simon-weber/7853144
|
332 |
+
A context manager that will prevent any logging messages triggered during the body from being processed.
|
333 |
+
:param highest_level: the maximum logging level in use.
|
334 |
+
This would only need to be changed if a custom level greater than CRITICAL is defined.
|
335 |
+
"""
|
336 |
+
previous_level = logging.root.manager.disable
|
337 |
+
logging.disable(highest_level)
|
338 |
+
try:
|
339 |
+
yield
|
340 |
+
finally:
|
341 |
+
logging.disable(previous_level)
|