WorkingDirectory
Bases: contextlib.ContextDecorator
Usage: @WorkingDirectory(dir) decorator or 'with WorkingDirectory(dir):' context manager.
Source code in ultralytics/yolo/utils/files.py
__enter__()
__exit__(exc_type, exc_val, exc_tb)
__init__(new_dir)
increment_path
Increments a file or directory path, i.e. runs/exp --> runs/exp{sep}2, runs/exp{sep}3, ... etc.
If the path exists and exist_ok is not set to True, the path will be incremented by appending a number and sep to the end of the path. If the path is a file, the file extension will be preserved. If the path is a directory, the number will be appended directly to the end of the path. If mkdir is set to True, the path will be created as a directory if it does not already exist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str, pathlib.Path
|
Path to increment. |
required |
exist_ok |
bool
|
If True, the path will not be incremented and returned as-is. Defaults to False. |
False
|
sep |
str
|
Separator to use between the path and the incrementation number. Defaults to ''. |
''
|
mkdir |
bool
|
Create a directory if it does not exist. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
pathlib.Path
|
Incremented path. |
Source code in ultralytics/yolo/utils/files.py
file_age
file_date
file_size
Return file/dir size (MB).
Source code in ultralytics/yolo/utils/files.py
get_latest_run
Return path to most recent 'last.pt' in /runs (i.e. to --resume from).
Source code in ultralytics/yolo/utils/files.py
make_dirs
Created 2023-04-16, Updated 2023-05-17
Authors: Glenn Jocher (4)