From 3f34a7c3afd3cb94f839ea06b522d9c6a5093985 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 7 Apr 2024 00:05:32 +0200 Subject: [PATCH] New `is_raspberrypi` function (#9826) Co-authored-by: UltralyticsAssistant Co-authored-by: Lakshantha Dissanayake --- ultralytics/utils/__init__.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ultralytics/utils/__init__.py b/ultralytics/utils/__init__.py index 9aaf0fd7..fb86e8a0 100644 --- a/ultralytics/utils/__init__.py +++ b/ultralytics/utils/__init__.py @@ -460,12 +460,23 @@ def is_docker() -> bool: Returns: (bool): True if the script is running inside a Docker container, False otherwise. """ - file = Path("/proc/self/cgroup") - if file.exists(): - with open(file) as f: + with contextlib.suppress(Exception): + with open("/proc/self/cgroup") as f: return "docker" in f.read() - else: - return False + return False + + +def is_raspberrypi() -> bool: + """ + Determines if the Python environment is running on a Raspberry Pi by checking the device model information. + + Returns: + (bool): True if running on a Raspberry Pi, False otherwise. + """ + with contextlib.suppress(Exception): + with open("/proc/device-tree/model") as f: + return "Raspberry Pi" in f.read() + return False def is_online() -> bool: