ultralytics 8.1.44 add IS_RASPBERRYPI and constants refactor (#9827)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
parent
3f34a7c3af
commit
7d891a4aa4
43 changed files with 146 additions and 141 deletions
|
|
@ -495,9 +495,6 @@ def is_online() -> bool:
|
|||
return False
|
||||
|
||||
|
||||
ONLINE = is_online()
|
||||
|
||||
|
||||
def is_pip_package(filepath: str = __name__) -> bool:
|
||||
"""
|
||||
Determines if the file at the given filepath is part of a pip package.
|
||||
|
|
@ -550,17 +547,6 @@ def is_github_action_running() -> bool:
|
|||
return "GITHUB_ACTIONS" in os.environ and "GITHUB_WORKFLOW" in os.environ and "RUNNER_OS" in os.environ
|
||||
|
||||
|
||||
def is_git_dir():
|
||||
"""
|
||||
Determines whether the current file is part of a git repository. If the current file is not part of a git
|
||||
repository, returns None.
|
||||
|
||||
Returns:
|
||||
(bool): True if current file is part of a git repository.
|
||||
"""
|
||||
return get_git_dir() is not None
|
||||
|
||||
|
||||
def get_git_dir():
|
||||
"""
|
||||
Determines whether the current file is part of a git repository and if so, returns the repository root directory. If
|
||||
|
|
@ -574,6 +560,17 @@ def get_git_dir():
|
|||
return d
|
||||
|
||||
|
||||
def is_git_dir():
|
||||
"""
|
||||
Determines whether the current file is part of a git repository. If the current file is not part of a git
|
||||
repository, returns None.
|
||||
|
||||
Returns:
|
||||
(bool): True if current file is part of a git repository.
|
||||
"""
|
||||
return GIT_DIR is not None
|
||||
|
||||
|
||||
def get_git_origin_url():
|
||||
"""
|
||||
Retrieves the origin URL of a git repository.
|
||||
|
|
@ -581,7 +578,7 @@ def get_git_origin_url():
|
|||
Returns:
|
||||
(str | None): The origin URL of the git repository or None if not git directory.
|
||||
"""
|
||||
if is_git_dir():
|
||||
if IS_GIT_DIR:
|
||||
with contextlib.suppress(subprocess.CalledProcessError):
|
||||
origin = subprocess.check_output(["git", "config", "--get", "remote.origin.url"])
|
||||
return origin.decode().strip()
|
||||
|
|
@ -594,7 +591,7 @@ def get_git_branch():
|
|||
Returns:
|
||||
(str | None): The current git branch name or None if not a git directory.
|
||||
"""
|
||||
if is_git_dir():
|
||||
if IS_GIT_DIR:
|
||||
with contextlib.suppress(subprocess.CalledProcessError):
|
||||
origin = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])
|
||||
return origin.decode().strip()
|
||||
|
|
@ -660,6 +657,16 @@ def get_user_config_dir(sub_dir="Ultralytics"):
|
|||
return path
|
||||
|
||||
|
||||
# Define constants (required below)
|
||||
ONLINE = is_online()
|
||||
IS_COLAB = is_colab()
|
||||
IS_DOCKER = is_docker()
|
||||
IS_JUPYTER = is_jupyter()
|
||||
IS_KAGGLE = is_kaggle()
|
||||
IS_PIP_PACKAGE = is_pip_package()
|
||||
IS_RASPBERRYPI = is_raspberrypi()
|
||||
GIT_DIR = get_git_dir()
|
||||
IS_GIT_DIR = is_git_dir()
|
||||
USER_CONFIG_DIR = Path(os.getenv("YOLO_CONFIG_DIR") or get_user_config_dir()) # Ultralytics settings dir
|
||||
SETTINGS_YAML = USER_CONFIG_DIR / "settings.yaml"
|
||||
|
||||
|
|
@ -886,7 +893,7 @@ def set_sentry():
|
|||
event["tags"] = {
|
||||
"sys_argv": ARGV[0],
|
||||
"sys_argv_name": Path(ARGV[0]).name,
|
||||
"install": "git" if is_git_dir() else "pip" if is_pip_package() else "other",
|
||||
"install": "git" if IS_GIT_DIR else "pip" if IS_PIP_PACKAGE else "other",
|
||||
"os": ENVIRONMENT,
|
||||
}
|
||||
return event
|
||||
|
|
@ -897,8 +904,8 @@ def set_sentry():
|
|||
and Path(ARGV[0]).name == "yolo"
|
||||
and not TESTS_RUNNING
|
||||
and ONLINE
|
||||
and is_pip_package()
|
||||
and not is_git_dir()
|
||||
and IS_PIP_PACKAGE
|
||||
and not IS_GIT_DIR
|
||||
):
|
||||
# If sentry_sdk package is not installed then return and do not use Sentry
|
||||
try:
|
||||
|
|
@ -937,9 +944,8 @@ class SettingsManager(dict):
|
|||
from ultralytics.utils.checks import check_version
|
||||
from ultralytics.utils.torch_utils import torch_distributed_zero_first
|
||||
|
||||
git_dir = get_git_dir()
|
||||
root = git_dir or Path()
|
||||
datasets_root = (root.parent if git_dir and is_dir_writeable(root.parent) else root).resolve()
|
||||
root = GIT_DIR or Path()
|
||||
datasets_root = (root.parent if GIT_DIR and is_dir_writeable(root.parent) else root).resolve()
|
||||
|
||||
self.file = Path(file)
|
||||
self.version = version
|
||||
|
|
@ -1043,13 +1049,13 @@ WEIGHTS_DIR = Path(SETTINGS["weights_dir"]) # global weights directory
|
|||
RUNS_DIR = Path(SETTINGS["runs_dir"]) # global runs directory
|
||||
ENVIRONMENT = (
|
||||
"Colab"
|
||||
if is_colab()
|
||||
if IS_COLAB
|
||||
else "Kaggle"
|
||||
if is_kaggle()
|
||||
if IS_KAGGLE
|
||||
else "Jupyter"
|
||||
if is_jupyter()
|
||||
if IS_JUPYTER
|
||||
else "Docker"
|
||||
if is_docker()
|
||||
if IS_DOCKER
|
||||
else platform.system()
|
||||
)
|
||||
TESTS_RUNNING = is_pytest_running() or is_github_action_running()
|
||||
|
|
|
|||
|
|
@ -12,10 +12,7 @@ def on_pretrain_routine_end(trainer):
|
|||
session = getattr(trainer, "hub_session", None)
|
||||
if session:
|
||||
# Start timer for upload rate limit
|
||||
session.timers = {
|
||||
"metrics": time(),
|
||||
"ckpt": time(),
|
||||
} # start timer on session.rate_limit
|
||||
session.timers = {"metrics": time(), "ckpt": time()} # start timer on session.rate_limit
|
||||
|
||||
|
||||
def on_fit_epoch_end(trainer):
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ def on_pretrain_routine_end(trainer):
|
|||
MLFLOW_TRACKING_URI: The URI for MLflow tracking. If not set, defaults to 'runs/mlflow'.
|
||||
MLFLOW_EXPERIMENT_NAME: The name of the MLflow experiment. If not set, defaults to trainer.args.project.
|
||||
MLFLOW_RUN: The name of the MLflow run. If not set, defaults to trainer.args.name.
|
||||
MLFLOW_KEEP_RUN_ACTIVE: Boolean indicating whether to keep the MLflow run active after the end of the training phase.
|
||||
MLFLOW_KEEP_RUN_ACTIVE: Boolean indicating whether to keep the MLflow run active after the end of training.
|
||||
"""
|
||||
global mlflow
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ try:
|
|||
# Imports below only required if TensorBoard enabled
|
||||
import warnings
|
||||
from copy import deepcopy
|
||||
|
||||
from ultralytics.utils.torch_utils import de_parallel, torch
|
||||
|
||||
except (ImportError, AssertionError, TypeError, AttributeError):
|
||||
|
|
|
|||
|
|
@ -22,10 +22,15 @@ import torch
|
|||
from ultralytics.utils import (
|
||||
ASSETS,
|
||||
AUTOINSTALL,
|
||||
IS_COLAB,
|
||||
IS_DOCKER,
|
||||
IS_JUPYTER,
|
||||
IS_KAGGLE,
|
||||
IS_PIP_PACKAGE,
|
||||
LINUX,
|
||||
LOGGER,
|
||||
PYTHON_VERSION,
|
||||
ONLINE,
|
||||
PYTHON_VERSION,
|
||||
ROOT,
|
||||
TORCHVISION_VERSION,
|
||||
USER_CONFIG_DIR,
|
||||
|
|
@ -37,12 +42,7 @@ from ultralytics.utils import (
|
|||
colorstr,
|
||||
downloads,
|
||||
emojis,
|
||||
is_colab,
|
||||
is_docker,
|
||||
is_github_action_running,
|
||||
is_jupyter,
|
||||
is_kaggle,
|
||||
is_pip_package,
|
||||
url2file,
|
||||
)
|
||||
|
||||
|
|
@ -277,7 +277,7 @@ def check_pip_update_available():
|
|||
Returns:
|
||||
(bool): True if an update is available, False otherwise.
|
||||
"""
|
||||
if ONLINE and is_pip_package():
|
||||
if ONLINE and IS_PIP_PACKAGE:
|
||||
with contextlib.suppress(Exception):
|
||||
from ultralytics import __version__
|
||||
|
||||
|
|
@ -528,7 +528,7 @@ def check_imshow(warn=False):
|
|||
"""Check if environment supports image displays."""
|
||||
try:
|
||||
if LINUX:
|
||||
assert "DISPLAY" in os.environ and not is_docker() and not is_colab() and not is_kaggle()
|
||||
assert "DISPLAY" in os.environ and not IS_DOCKER and not IS_COLAB and not IS_KAGGLE
|
||||
cv2.imshow("test", np.zeros((8, 8, 3), dtype=np.uint8)) # show a small 8-pixel image
|
||||
cv2.waitKey(1)
|
||||
cv2.destroyAllWindows()
|
||||
|
|
@ -546,10 +546,10 @@ def check_yolo(verbose=True, device=""):
|
|||
|
||||
from ultralytics.utils.torch_utils import select_device
|
||||
|
||||
if is_jupyter():
|
||||
if IS_JUPYTER:
|
||||
if check_requirements("wandb", install=False):
|
||||
os.system("pip uninstall -y wandb") # uninstall wandb: unwanted account creation prompt with infinite hang
|
||||
if is_colab():
|
||||
if IS_COLAB:
|
||||
shutil.rmtree("sample_data", ignore_errors=True) # remove colab /sample_data directory
|
||||
|
||||
if verbose:
|
||||
|
|
@ -574,7 +574,7 @@ def collect_system_info():
|
|||
|
||||
import psutil
|
||||
|
||||
from ultralytics.utils import ENVIRONMENT, is_git_dir
|
||||
from ultralytics.utils import ENVIRONMENT, IS_GIT_DIR
|
||||
from ultralytics.utils.torch_utils import get_cpu_info
|
||||
|
||||
ram_info = psutil.virtual_memory().total / (1024**3) # Convert bytes to GB
|
||||
|
|
@ -583,7 +583,7 @@ def collect_system_info():
|
|||
f"\n{'OS':<20}{platform.platform()}\n"
|
||||
f"{'Environment':<20}{ENVIRONMENT}\n"
|
||||
f"{'Python':<20}{PYTHON_VERSION}\n"
|
||||
f"{'Install':<20}{'git' if is_git_dir() else 'pip' if is_pip_package() else 'other'}\n"
|
||||
f"{'Install':<20}{'git' if IS_GIT_DIR else 'pip' if IS_PIP_PACKAGE else 'other'}\n"
|
||||
f"{'RAM':<20}{ram_info:.2f} GB\n"
|
||||
f"{'CPU':<20}{get_cpu_info()}\n"
|
||||
f"{'CUDA':<20}{torch.version.cuda if torch and torch.cuda.is_available() else None}\n"
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ from ultralytics.utils import (
|
|||
LOGGER,
|
||||
PYTHON_VERSION,
|
||||
TORCHVISION_VERSION,
|
||||
colorstr,
|
||||
__version__,
|
||||
colorstr,
|
||||
)
|
||||
from ultralytics.utils.checks import check_version
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue