diff --git a/docker/hailo8l/Dockerfile b/docker/hailo8l/Dockerfile index 2e91563d4..881fcf594 100644 --- a/docker/hailo8l/Dockerfile +++ b/docker/hailo8l/Dockerfile @@ -77,8 +77,6 @@ FROM deps AS h8l-frigate COPY --from=h8l-wheels /h8l-wheels /deps/h8l-wheels COPY --from=build-hailort /hailo-wheels /deps/hailo-wheels COPY --from=build-hailort /etc/environment /etc/environment -RUN mkdir /hailo8l_models -RUN wget -O /hailo8l_models/ssd_mobilenet_v1.hef https://hailo-model-zoo.s3.eu-west-2.amazonaws.com/ModelZoo/Compiled/v2.11.0/hailo8l/ssd_mobilenet_v1.hef RUN CC=$(python3 -c "import sysconfig; import shlex; cc = sysconfig.get_config_var('CC'); cc_cmd = shlex.split(cc)[0]; print(cc_cmd[:-4] if cc_cmd.endswith('-gcc') else cc_cmd)") && \ echo "CC=$CC" >> /etc/environment diff --git a/docs/docs/configuration/object_detectors.md b/docs/docs/configuration/object_detectors.md index efb33ddda..bde37432e 100644 --- a/docs/docs/configuration/object_detectors.md +++ b/docs/docs/configuration/object_detectors.md @@ -398,7 +398,7 @@ $ cat /sys/kernel/debug/rknpu/load This detector is available if you are using the Raspberry Pi 5 with Hailo-8L AI Kit. This has not been tested using the Hailo-8L with other hardware. -### Configuration +### Configuration ```yaml detectors: @@ -406,7 +406,7 @@ detectors: type: hailo8l device: PCIe model: - path: /hailo8l_models/ssd_mobilenet_v1.hef + path: /config/model_cache/h8l_cache/ssd_mobilenet_v1.hef model: width: 300 diff --git a/frigate/detectors/plugins/hailo8l.py b/frigate/detectors/plugins/hailo8l.py index 88b542a5e..cb797baeb 100644 --- a/frigate/detectors/plugins/hailo8l.py +++ b/frigate/detectors/plugins/hailo8l.py @@ -1,4 +1,6 @@ import logging +import os +import urllib.request import numpy as np from hailo_platform import ( @@ -50,9 +52,13 @@ class HailoDetector(DetectionApi): self.h8l_model_type = detector_config.model.model_type self.h8l_tensor_format = detector_config.model.input_tensor self.h8l_pixel_format = detector_config.model.input_pixel_format + self.model_url = "https://hailo-model-zoo.s3.eu-west-2.amazonaws.com/ModelZoo/Compiled/v2.11.0/hailo8l/ssd_mobilenet_v1.hef" + self.cache_dir = "/config/model_cache/h8l_cache" + self.expected_model_filename = "ssd_mobilenet_v1.hef" output_type = "FLOAT32" logger.info(f"Initializing Hailo device as {self.h8l_device_type}") + self.check_and_prepare_model() try: # Validate device type if self.h8l_device_type not in ["PCIe", "M.2"]: @@ -99,6 +105,24 @@ class HailoDetector(DetectionApi): logger.error(f"Failed to initialize Hailo device: {e}") raise + def check_and_prepare_model(self): + # Ensure cache directory exists + if not os.path.exists(self.cache_dir): + os.makedirs(self.cache_dir) + + # Check for the expected model file + model_file_path = os.path.join(self.cache_dir, self.expected_model_filename) + if not os.path.isfile(model_file_path): + logger.info( + f"A model file was not found at {model_file_path}, Downloading one from {self.model_url}." + ) + urllib.request.urlretrieve(self.model_url, model_file_path) + logger.info(f"A model file was downloaded to {model_file_path}.") + else: + logger.info( + f"A model file already exists at {model_file_path} not downloading one." + ) + def detect_raw(self, tensor_input): logger.debug("[detect_raw] Entering function") logger.debug(