From f777b63c8baf8b733d3ddd6e41e42bbd7c88778e Mon Sep 17 00:00:00 2001 From: Francesco Mattioli Date: Fri, 17 Jan 2025 12:48:49 +0100 Subject: [PATCH] `ultralytics 8.3.63` IMX500 sudo install fix (#18714) Signed-off-by: Glenn Jocher Co-authored-by: UltralyticsAssistant Co-authored-by: Glenn Jocher --- docs/en/reference/utils/checks.md | 4 ++++ ultralytics/__init__.py | 2 +- ultralytics/engine/exporter.py | 16 ++++++++++++---- ultralytics/utils/checks.py | 12 ++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/docs/en/reference/utils/checks.md b/docs/en/reference/utils/checks.md index 378af7e8..74286401 100644 --- a/docs/en/reference/utils/checks.md +++ b/docs/en/reference/utils/checks.md @@ -109,4 +109,8 @@ keywords: Ultralytics, YOLO, utility functions, version checks, requirements, im ## ::: ultralytics.utils.checks.cuda_is_available +



+ +## ::: ultralytics.utils.checks.is_sudo_available +

diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index d1930b9c..d15296f1 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license -__version__ = "8.3.62" +__version__ = "8.3.63" import os diff --git a/ultralytics/engine/exporter.py b/ultralytics/engine/exporter.py index 56f8ed06..37c994ef 100644 --- a/ultralytics/engine/exporter.py +++ b/ultralytics/engine/exporter.py @@ -91,7 +91,13 @@ from ultralytics.utils import ( get_default_args, yaml_save, ) -from ultralytics.utils.checks import check_imgsz, check_is_path_safe, check_requirements, check_version +from ultralytics.utils.checks import ( + check_imgsz, + check_is_path_safe, + check_requirements, + check_version, + is_sudo_available, +) from ultralytics.utils.downloads import attempt_download_asset, get_github_assets, safe_download from ultralytics.utils.files import file_size, spaces_in_path from ultralytics.utils.ops import Profile @@ -1071,7 +1077,6 @@ class Exporter: assert LINUX, f"export only supported on Linux. See {help_url}" if subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, shell=True).returncode != 0: LOGGER.info(f"\n{prefix} export requires Edge TPU compiler. Attempting install from {help_url}") - sudo = subprocess.run("sudo --version >/dev/null", shell=True).returncode == 0 # sudo installed on system for c in ( "curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -", 'echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | ' @@ -1079,7 +1084,7 @@ class Exporter: "sudo apt-get update", "sudo apt-get install edgetpu-compiler", ): - subprocess.run(c if sudo else c.replace("sudo ", ""), shell=True, check=True) + subprocess.run(c if is_sudo_available() else c.replace("sudo ", ""), shell=True, check=True) ver = subprocess.run(cmd, shell=True, capture_output=True, check=True).stdout.decode().split()[-1] LOGGER.info(f"\n{prefix} starting export with Edge TPU compiler {ver}...") @@ -1160,7 +1165,10 @@ class Exporter: if "openjdk 17" not in str(out.stdout): raise FileNotFoundError except FileNotFoundError: - subprocess.run(["sudo", "apt", "install", "-y", "openjdk-17-jdk", "openjdk-17-jre"], check=True) + c = ["apt", "install", "-y", "openjdk-17-jdk", "openjdk-17-jre"] + if is_sudo_available(): + c.insert(0, "sudo") + subprocess.run(c, check=True) def representative_dataset_gen(dataloader=self.get_int8_calibration_dataloader(prefix)): for batch in dataloader: diff --git a/ultralytics/utils/checks.py b/ultralytics/utils/checks.py index b3162711..a58d602d 100644 --- a/ultralytics/utils/checks.py +++ b/ultralytics/utils/checks.py @@ -782,6 +782,18 @@ def cuda_is_available() -> bool: return cuda_device_count() > 0 +def is_sudo_available() -> bool: + """ + Check if the sudo command is available in the environment. + + Returns: + bool: True if the sudo command is available, False otherwise. + """ + if WINDOWS: + return False + return subprocess.run(["sudo", "--version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0 + + # Run checks and define constants check_python("3.8", hard=False, verbose=True) # check python version check_torchvision() # check torch-torchvision compatibility