From 0e48a00303f02b0ae3b1c1351d06d67759a6edff Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 24 Jan 2025 10:53:56 +0100 Subject: [PATCH] Add `YOLO_TQDM_RICH` environment variable (#18854) Co-authored-by: UltralyticsAssistant --- ultralytics/utils/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ultralytics/utils/__init__.py b/ultralytics/utils/__init__.py index f3aee7b5..3afa07a9 100644 --- a/ultralytics/utils/__init__.py +++ b/ultralytics/utils/__init__.py @@ -13,6 +13,7 @@ import sys import threading import time import uuid +import warnings from pathlib import Path from threading import Lock from types import SimpleNamespace @@ -132,8 +133,11 @@ os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" # suppress verbose TF compiler warning os.environ["TORCH_CPP_LOG_LEVEL"] = "ERROR" # suppress "NNPACK.cpp could not initialize NNPACK" warnings os.environ["KINETO_LOG_LEVEL"] = "5" # suppress verbose PyTorch profiler output when computing FLOPs +if TQDM_RICH := str(os.getenv("YOLO_TQDM_RICH", False)).lower() == "true": + from tqdm import rich -class TQDM(tqdm.tqdm): + +class TQDM(rich.tqdm if TQDM_RICH else tqdm.tqdm): """ A custom TQDM progress bar class that extends the original tqdm functionality. @@ -176,7 +180,8 @@ class TQDM(tqdm.tqdm): ... # Your code here ... pass """ - kwargs["disable"] = not VERBOSE or kwargs.get("disable", False) # logical 'and' with default value if passed + warnings.filterwarnings("ignore", category=tqdm.TqdmExperimentalWarning) # suppress tqdm.rich warning + kwargs["disable"] = not VERBOSE or kwargs.get("disable", False) kwargs.setdefault("bar_format", TQDM_BAR_FORMAT) # override default value if passed super().__init__(*args, **kwargs)