Add IS_JETSON constant (#9852)

Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
Glenn Jocher 2024-04-08 12:25:02 +02:00 committed by GitHub
parent 01b34a483c
commit f2ddc96334
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -406,6 +406,20 @@ DEFAULT_CFG_KEYS = DEFAULT_CFG_DICT.keys()
DEFAULT_CFG = IterableSimpleNamespace(**DEFAULT_CFG_DICT) DEFAULT_CFG = IterableSimpleNamespace(**DEFAULT_CFG_DICT)
def read_device_model() -> str:
"""
Reads the device model information from the system and caches it for quick access. Used by is_jetson() and
is_raspberrypi().
Returns:
(str): Model file contents if read successfully or empty string otherwise.
"""
with contextlib.suppress(Exception):
with open("/proc/device-tree/model") as f:
return f.read()
return ""
def is_ubuntu() -> bool: def is_ubuntu() -> bool:
""" """
Check if the OS is Ubuntu. Check if the OS is Ubuntu.
@ -473,10 +487,18 @@ def is_raspberrypi() -> bool:
Returns: Returns:
(bool): True if running on a Raspberry Pi, False otherwise. (bool): True if running on a Raspberry Pi, False otherwise.
""" """
with contextlib.suppress(Exception): return "Raspberry Pi" in PROC_DEVICE_MODEL
with open("/proc/device-tree/model") as f:
return "Raspberry Pi" in f.read()
return False def is_jetson() -> bool:
"""
Determines if the Python environment is running on a Jetson Nano or Jetson Orin device by checking the device model
information.
Returns:
(bool): True if running on a Jetson Nano or Jetson Orin, False otherwise.
"""
return "Jetson" in PROC_DEVICE_MODEL # i.e. "Jetson Nano" or "Jetson Orin"
def is_online() -> bool: def is_online() -> bool:
@ -658,9 +680,11 @@ def get_user_config_dir(sub_dir="Ultralytics"):
# Define constants (required below) # Define constants (required below)
PROC_DEVICE_MODEL = read_device_model() # is_jetson() and is_raspberrypi() depend on this constant
ONLINE = is_online() ONLINE = is_online()
IS_COLAB = is_colab() IS_COLAB = is_colab()
IS_DOCKER = is_docker() IS_DOCKER = is_docker()
IS_JETSON = is_jetson()
IS_JUPYTER = is_jupyter() IS_JUPYTER = is_jupyter()
IS_KAGGLE = is_kaggle() IS_KAGGLE = is_kaggle()
IS_PIP_PACKAGE = is_pip_package() IS_PIP_PACKAGE = is_pip_package()
@ -696,8 +720,8 @@ def colorstr(*input):
(str): The input string wrapped with ANSI escape codes for the specified color and style. (str): The input string wrapped with ANSI escape codes for the specified color and style.
Examples: Examples:
>>> colorstr('blue', 'bold', 'hello world') >>> colorstr("blue", "bold", "hello world")
>>> '\033[34m\033[1mhello world\033[0m' >>> "\033[34m\033[1mhello world\033[0m"
""" """
*args, string = input if len(input) > 1 else ("blue", "bold", input[0]) # color arguments, string *args, string = input if len(input) > 1 else ("blue", "bold", input[0]) # color arguments, string
colors = { colors = {