Updated dockerfile so it dose not download the model file.

add function to download it at runtime.

update model path.
This commit is contained in:
spanner3003 2024-07-13 21:23:10 +01:00
parent 511b446631
commit b60f4ff905
3 changed files with 26 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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(