Skip to content

Commit

Permalink
Allow use of prior cached model
Browse files Browse the repository at this point in the history
Moving the requests.get(url) below the check for cache.  If your vision system is offline, and you have a cached model, the check prior to checking cache throws an exception.  Now if you have a cached model it will use that first and only if you dont have a model will it switch to checking api.roboflow.com
  • Loading branch information
dlaflotte committed Feb 9, 2024
1 parent 3c008f3 commit 46c7226
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions depthai_sdk/src/depthai_sdk/integrations/roboflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ def _file_with_ext(self, folder: Path, ext: str) -> Optional[Path]:

def device_update(self, device: dai.Device) -> Path:
mxid = device.getMxId()
url = f"https://api.roboflow.com/depthai/{self.config['model']}/?api_key={self.config['key']}&device={mxid}"
response = requests.get(url)

name = self.config['model'].replace('/', '_') # '/' isn't valid folder name

model_folder = ROBOFLOW_MODELS / name
json_file = self._file_with_ext(model_folder, '.json')
if json_file:
return json_file

#Check the URL after checking the cache to make sure vision systems that are offline don't throw an exception
url = f"https://api.roboflow.com/depthai/{self.config['model']}/?api_key={self.config['key']}&device={mxid}"
response = requests.get(url)


json_res = response.json()
if "error" in json_res:
raise Exception(json_res['error'])
Expand Down

0 comments on commit 46c7226

Please sign in to comment.