Reference for ultralytics/utils/tqdm.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/tqdm.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.utils.tqdm.TQDM
TQDM(
iterable: Any = None,
desc: str | None = None,
total: int | None = None,
leave: bool = True,
file: IO[str] | None = None,
mininterval: float = 0.1,
disable: bool | None = None,
unit: str = "it",
unit_scale: bool = False,
unit_divisor: int = 1000,
bar_format: str | None = None,
initial: int = 0,
**kwargs
)
Lightweight zero-dependency progress bar for Ultralytics.
Provides clean, rich-style progress bars suitable for various environments including Weights & Biases, console outputs, and other logging systems. Features zero external dependencies, clean single-line output, rich-style progress bars with Unicode block characters, context manager support, iterator protocol support, and dynamic description updates.
Attributes:
Name | Type | Description |
---|---|---|
iterable |
object
|
Iterable to wrap with progress bar. |
desc |
str
|
Prefix description for the progress bar. |
total |
int
|
Expected number of iterations. |
disable |
bool
|
Whether to disable the progress bar. |
unit |
str
|
String for units of iteration. |
unit_scale |
bool
|
Auto-scale units flag. |
unit_divisor |
int
|
Divisor for unit scaling. |
leave |
bool
|
Whether to leave the progress bar after completion. |
mininterval |
float
|
Minimum time interval between updates. |
initial |
int
|
Initial counter value. |
n |
int
|
Current iteration count. |
closed |
bool
|
Whether the progress bar is closed. |
bar_format |
str
|
Custom bar format string. |
file |
object
|
Output file stream. |
Methods:
Name | Description |
---|---|
update |
Update progress by n steps. |
set_description |
Set or update the description. |
set_postfix |
Set postfix for the progress bar. |
close |
Close the progress bar and clean up. |
refresh |
Refresh the progress bar display. |
clear |
Clear the progress bar from display. |
write |
Write a message without breaking the progress bar. |
Examples:
Basic usage with iterator:
>>> for i in TQDM(range(100)):
... time.sleep(0.01)
With custom description:
>>> pbar = TQDM(range(100), desc="Processing")
>>> for i in pbar:
... pbar.set_description(f"Processing item {i}")
Context manager usage:
>>> with TQDM(total=100, unit="B", unit_scale=True) as pbar:
... for i in range(100):
... pbar.update(1)
Manual updates:
>>> pbar = TQDM(total=100, desc="Training")
>>> for epoch in range(100):
... # Do work
... pbar.update(1)
>>> pbar.close()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterable
|
object
|
Iterable to wrap with progress bar. |
None
|
desc
|
str
|
Prefix description for the progress bar. |
None
|
total
|
int
|
Expected number of iterations. |
None
|
leave
|
bool
|
Whether to leave the progress bar after completion. |
True
|
file
|
object
|
Output file stream for progress display. |
None
|
mininterval
|
float
|
Minimum time interval between updates (default 0.1s, 60s in GitHub Actions). |
0.1
|
disable
|
bool
|
Whether to disable the progress bar. Auto-detected if None. |
None
|
unit
|
str
|
String for units of iteration (default "it" for items). |
'it'
|
unit_scale
|
bool
|
Auto-scale units for bytes/data units. |
False
|
unit_divisor
|
int
|
Divisor for unit scaling (default 1000). |
1000
|
bar_format
|
str
|
Custom bar format string. |
None
|
initial
|
int
|
Initial counter value. |
0
|
**kwargs
|
Any
|
Additional keyword arguments for compatibility (ignored). |
{}
|
Examples:
>>> pbar = TQDM(range(100), desc="Processing")
>>> with TQDM(total=1000, unit="B", unit_scale=True) as pbar:
... pbar.update(1024) # Updates by 1KB
Source code in ultralytics/utils/tqdm.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
__del__
__del__() -> None
Destructor to ensure cleanup.
Source code in ultralytics/utils/tqdm.py
377 378 379 380 381 382 |
|
__enter__
__enter__() -> TQDM
Enter context manager.
Source code in ultralytics/utils/tqdm.py
357 358 359 |
|
__exit__
__exit__(*args: Any) -> None
Exit context manager and close progress bar.
Source code in ultralytics/utils/tqdm.py
361 362 363 |
|
__iter__
__iter__() -> Any
Iterate over the wrapped iterable with progress updates.
Source code in ultralytics/utils/tqdm.py
365 366 367 368 369 370 371 372 373 374 375 |
|
clear
clear() -> None
Clear progress bar.
Source code in ultralytics/utils/tqdm.py
389 390 391 392 393 394 395 396 |
|
close
close() -> None
Close progress bar.
Source code in ultralytics/utils/tqdm.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
refresh
refresh() -> None
Refresh display.
Source code in ultralytics/utils/tqdm.py
384 385 386 387 |
|
set_description
set_description(desc: str | None) -> None
Set description.
Source code in ultralytics/utils/tqdm.py
320 321 322 323 324 |
|
set_postfix
set_postfix(**kwargs: Any) -> None
Set postfix (appends to description).
Source code in ultralytics/utils/tqdm.py
326 327 328 329 330 331 |
|
update
update(n: int = 1) -> None
Update progress by n steps.
Source code in ultralytics/utils/tqdm.py
314 315 316 317 318 |
|
write
staticmethod
write(s: str, file: IO[str] | None = None, end: str = '\n') -> None
Static method to write without breaking progress bar.
Source code in ultralytics/utils/tqdm.py
398 399 400 401 402 403 404 405 406 |
|
ultralytics.utils.tqdm.is_noninteractive_console
cached
is_noninteractive_console() -> bool
Check for known non-interactive console environments.
Source code in ultralytics/utils/tqdm.py
12 13 14 15 |
|