Error while running model.py file.
error : raise Exception(“Failure while retrying load weights - does this model, version, api key exist? can you curl api.roboflow.com, and can your device download files from google cloud storage? have you hit your device limit?”)
Exception: Failure while retrying load weights - does this model, version, api key exist? can you curl api.roboflow.com, and can your device download files from google cloud storage? have you hit your device limit?
I have installed roboflowoak using pip and changed the api , version and model in the python code available on luxonis deployment page.
Hi @priyam_dalwadi - I’ve seen this error before, and believe I know the issue. However, let’s investigate further to make sure.
Are you pulling from a generated dataset version that was trained with Roboflow Train 2.0?
The roboflowoak
package is optimized only for dataset versions trained with Roboflow Train 2.0, and not Roboflow Train 1.0.
If you did pull from a dataset version trained with Roboflow Train 2.0, can you confirm you have structured your python file like mine, and you have DepthAI on your host device the OAK is connected?
Example Code includes model-id
and version-number
from my Face Detection dataset (PRIVATE_API_KEY
is omitted for security reasons, and setting a device_name
is optional).
from roboflowoak import RoboflowOak
import cv2
import time
import numpy as np
if __name__ == '__main__':
# instantiating an object (rf) with the RoboflowOak module
rf = RoboflowOak(model="face-detection-mik1i", confidence=0.05,
overlap=0.5, version="7", api_key="YOUR-PRIVATE_API_KEY", rgb=True,
depth=True, device=None, device_name="", blocking=True)
while True:
t0 = time.time()
result, frame, raw_frame, depth = rf.detect(visualize=True)
predictions = result["predictions"]
#{
# predictions:
# [ {
# x: (middle),
# y:(middle),
# width: ,
# height: ,
# depth: ###->,
# confidence: ,
# class: ,
# mask: { }
# }
# ]
#}
#frame - frame after preprocs, with predictions
#raw_frame - original frame from your OAK
#depth - depth map for raw_frame, center-rectified to the center camera
#To access specific values within "predictions" use: [p.json() for p[a] in predictions]
# set "a" to the index value you are attempting to access
# Example: accessing the "y"-value: [p.json() for p[1] in predictions]
t = time.time()-t0
print("INFERENCE TIME IN MS ", 1/t)
print("PREDICTIONS ", [p.json() for p in predictions])
# setting parameters for depth calculation
max_depth = np.amax(depth)
cv2.imshow("depth", depth/max_depth)
# displaying the video feed as successive frames
cv2.imshow("frame", frame)
# how to close the OAK inference window / stop inference: CTRL+q or CTRL+c
if cv2.waitKey(1) == ord('q'):
break
I have generated my own dataset but I am not sure what version I am using. In web inference it shows version 1.
My code looks like this. I can run depthai_demo on my host machine as well.
if name == ‘main’:
# instantiating an object (rf) with the RoboflowOak module
rf = RoboflowOak(model=“barcodes-mgnia”, confidence=0.05, overlap=0.5,
version=“1”, api_key=“-------------”, rgb=True,
depth=True, device=None, blocking=True)
# Running our model and displaying the video output with detections
while True:
t0 = time.time()
# The rf.detect() function runs the model inference
result, frame, raw_frame, depth = rf.detect(visualize=True)
predictions = result[“predictions”]
# {
# predictions:
# [ {
# x: (middle),
# y:(middle),
# width:
# height:
# depth: ###->
# confidence:
# class:
# mask: {
# ]
# }
# frame - frame after preprocs, with predictions
# raw_frame - original frame from your OAK
# depth - depth map for raw_frame, center-rectified to the center camera
# timing: for benchmarking purposes
t = time.time() - t0
print("INFERENCE TIME IN MS ", 1 / t)
print("PREDICTIONS ", [p.json() for p in predictions])
# setting parameters for depth calculation
max_depth = np.amax(depth)
cv2.imshow("depth", depth / max_depth)
# displaying the video feed as successive frames
cv2.imshow("frame", frame)
# how to close the OAK inference window / stop inference: CTRL+q or CTRL+c
if cv2.waitKey(1) == ord('q'):
break
If it is version 1 that is trained in the web interface, then use version 1. The version number is listed directly on the dataset version.
I can’t tell how your file is indented due to the formatting of the reply, but so long as it is formatted like this, can you try again and let me know the result?
Can you help me with the version if its wrong / unsupported for OAK-D?
It looks correct if you entered version=1
in your code - did you receive an error again? What was it?
Additionally, do you have depthai
installed within your python environment?
This is the error I have got:
FilePATH\model1.py", line 8, in
rf = RoboflowOak(model=“barcodes-mgnia”,api_key=“-------”, confidence=0.05, overlap=0.5,
self.cache_path = self.find_weights()
PATH\roboflowoak_init_.py", line 59, in find_weights
return download_blob(self.project, self.version, self.api_key, self.dev)
PATH\api.py", line 15, in download_blob
raise Exception(str(api_data.json()))
PATH\models.py", line 910, in json
return complexjson.loads(self.text, **kwargs)
PATH\Python\Python310\lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
PATH\Python\Python310\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
PATH\Python\Python310\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
raise Exception(“Failure while retrying load weights - does this model, version, api key exist? can you curl api.roboflow.com, and can your device download files from google cloud storage? have you hit your device limit?”)
Exception: Failure while retrying load weights - does this model, version, api key exist? can you curl api.roboflow.com, and can your device download files from google cloud storage? have you hit your device limit?
When I run the code it shows device not found until it raise exception. But in same directory I am able to run depthai_demo.py file which runs perfectly well.
self.device = dai.Device(self.pipeline, device_info)
RuntimeError: ColorCamera(0) - ‘preview’ width or height (1088, 1088) bigger than sensor resolution (1920, 1080)
I found the error – your images need to be resized to under 1080x1080 for the model to load and run on your OAK correctly. v1
of your dataset was resized at 1080x1080 and caused an error in the blob conversion.
I recommend trying 416x416, 512x512, or 640x640. I just trained a v2
with 416x416 for the Resize preprocessing, and it ran fine on my OAK:
Just remember to update the version=1
to version=2
if you want to test the same model.