From 26f0d2d02b72546bee69349b9056dce97b928828 Mon Sep 17 00:00:00 2001 From: jakaskerl Date: Thu, 20 Feb 2025 19:17:31 +0100 Subject: [PATCH 1/2] Enabling NN component when offline --- .../src/depthai_sdk/components/nn_helper.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/depthai_sdk/src/depthai_sdk/components/nn_helper.py b/depthai_sdk/src/depthai_sdk/components/nn_helper.py index ef2ebbb18..6b15992be 100644 --- a/depthai_sdk/src/depthai_sdk/components/nn_helper.py +++ b/depthai_sdk/src/depthai_sdk/components/nn_helper.py @@ -8,21 +8,33 @@ BLOBS_PATH = Path.home() / Path('.cache/blobs') +BLOBS_PATH = Path.home() / Path('.cache/blobs') + def getBlob(url: str) -> Path: """ - Download the blob path from the url. If blob is cached, serve that. TODO: compute hash, check server hash, - as there will likely be many `model.blob`s. - - @param url: Url to the blob + Download the blob from the URL and cache it locally. + If the blob is already cached, return the cached file. + + @param url: URL to the blob @return: Local path to the blob """ fileName = Path(url).name filePath = BLOBS_PATH / fileName - if filePath.exists(): + + print(filePath) + + # Check if the cached file exists and is a file + if filePath.is_file(): return filePath + + # Ensure the blobs cache directory exists BLOBS_PATH.mkdir(parents=True, exist_ok=True) + # Download the blob r = requests.get(url) + if r.status_code != 200: + raise Exception(f"Failed to download {url}. Status code: {r.status_code}") + with open(filePath, 'wb') as f: f.write(r.content) print('Downloaded', fileName) From dfe81848da6448b39c9f64781ae692a9ba60a329 Mon Sep 17 00:00:00 2001 From: jakaskerl Date: Thu, 20 Feb 2025 19:24:19 +0100 Subject: [PATCH 2/2] Fix --- .../depthai_sdk/components/nn_component.py | 6 ++++- .../src/depthai_sdk/components/nn_helper.py | 22 +++++-------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/depthai_sdk/src/depthai_sdk/components/nn_component.py b/depthai_sdk/src/depthai_sdk/components/nn_component.py index 2341fd839..eb50557ad 100644 --- a/depthai_sdk/src/depthai_sdk/components/nn_component.py +++ b/depthai_sdk/src/depthai_sdk/components/nn_component.py @@ -240,7 +240,11 @@ def _parse_model(self, model): self._parse_config(model) else: # SDK supported model models = getSupportedModels(printModels=False) - zoo_models = blobconverter.zoo_list() + + try: + zoo_models = blobconverter.zoo_list() + except Exception as e: + LOGGER.warning("No internet access, can't load models from depthai zoo.") if str(model) in models: model = models[str(model)] / 'config.json' diff --git a/depthai_sdk/src/depthai_sdk/components/nn_helper.py b/depthai_sdk/src/depthai_sdk/components/nn_helper.py index 6b15992be..ef2ebbb18 100644 --- a/depthai_sdk/src/depthai_sdk/components/nn_helper.py +++ b/depthai_sdk/src/depthai_sdk/components/nn_helper.py @@ -8,33 +8,21 @@ BLOBS_PATH = Path.home() / Path('.cache/blobs') -BLOBS_PATH = Path.home() / Path('.cache/blobs') - def getBlob(url: str) -> Path: """ - Download the blob from the URL and cache it locally. - If the blob is already cached, return the cached file. - - @param url: URL to the blob + Download the blob path from the url. If blob is cached, serve that. TODO: compute hash, check server hash, + as there will likely be many `model.blob`s. + + @param url: Url to the blob @return: Local path to the blob """ fileName = Path(url).name filePath = BLOBS_PATH / fileName - - print(filePath) - - # Check if the cached file exists and is a file - if filePath.is_file(): + if filePath.exists(): return filePath - - # Ensure the blobs cache directory exists BLOBS_PATH.mkdir(parents=True, exist_ok=True) - # Download the blob r = requests.get(url) - if r.status_code != 200: - raise Exception(f"Failed to download {url}. Status code: {r.status_code}") - with open(filePath, 'wb') as f: f.write(r.content) print('Downloaded', fileName)