# Error while running python file

**URL:** <https://discuss.roboflow.com/t/error-while-running-python-file/616>\
**Category:** 🤝  Community Help\
**Created:** [June 29, 2022, 2:37pm UTC](https://discuss.roboflow.com/t/error-while-running-python-file/616 "2022-06-29T14:37:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![priyam\_dalwadi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/priyam_dalwadi/32/480_2.png) [@priyam\_dalwadi](https://discuss.roboflow.com/u/priyam_dalwadi)\
**Post date:** [June 29, 2022, 2:37pm UTC](https://discuss.roboflow.com/t/error-while-running-python-file/616/1 "2022-06-29T14:37:55Z")

</div>

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](http://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](http://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.

---

<div class="post-metadata">

**Author:** ![Mohamed](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/mohamed/32/62_2.png) [@Mohamed](https://discuss.roboflow.com/u/Mohamed)\
**Post date:** [June 29, 2022, 2:58pm UTC](https://discuss.roboflow.com/t/error-while-running-python-file/616/2 "2022-06-29T14:58:37Z")

</div>

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?

> **[New and Improved Roboflow Train](https://blog.roboflow.com/new-and-improved-roboflow-train/)**
>
> We incorporated advancements in computer vision research and learnings from users to create new training and deployment infrastructure.

The `roboflowoak` package is optimized only for dataset versions trained with Roboflow Train 2.0, and not Roboflow Train 1.0.

---

<div class="post-metadata">

**Author:** ![Mohamed](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/mohamed/32/62_2.png) [@Mohamed](https://discuss.roboflow.com/u/Mohamed)\
**Post date:** [June 29, 2022, 3:05pm UTC](https://discuss.roboflow.com/t/error-while-running-python-file/616/3 "2022-06-29T15:05:53Z")

</div>

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?

- [GitHub - luxonis/depthai: DepthAI Python API utilities, examples, and tutorials.](https://github.com/luxonis/depthai)
- [GitHub - luxonis/depthai-python: DepthAI Python Library](https://github.com/luxonis/depthai-python)

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).

```auto
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

```

---

<div class="post-metadata">

**Author:** ![priyam\_dalwadi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/priyam_dalwadi/32/480_2.png) [@priyam\_dalwadi](https://discuss.roboflow.com/u/priyam_dalwadi)\
**Post date:** [June 29, 2022, 3:09pm UTC](https://discuss.roboflow.com/t/error-while-running-python-file/616/4 "2022-06-29T15:09:34Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![Mohamed](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/mohamed/32/62_2.png) [@Mohamed](https://discuss.roboflow.com/u/Mohamed)\
**Post date:** [June 29, 2022, 3:40pm UTC](https://discuss.roboflow.com/t/error-while-running-python-file/616/5 "2022-06-29T15:40:30Z")

</div>

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.  
 ![image](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/da5caa09ee7df63f15d38fa4406c44521fa7ce2e.png)

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?

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/415cdd76a0ae02b4d32c27063488db56f5c011fe.png)

---

<div class="post-metadata">

**Author:** ![priyam\_dalwadi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/priyam_dalwadi/32/480_2.png) [@priyam\_dalwadi](https://discuss.roboflow.com/u/priyam_dalwadi)\
**Post date:** [June 29, 2022, 3:47pm UTC](https://discuss.roboflow.com/t/error-while-running-python-file/616/6 "2022-06-29T15:47:39Z")

</div>

![image](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/f4eed7e8a63ed4950fae92cf7ae485c41cd59d79.png)

Can you help me with the version if its wrong / unsupported for OAK-D?

---

<div class="post-metadata">

**Author:** ![Mohamed](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/mohamed/32/62_2.png) [@Mohamed](https://discuss.roboflow.com/u/Mohamed)\
**Post date:** [June 29, 2022, 3:50pm UTC](https://discuss.roboflow.com/t/error-while-running-python-file/616/7 "2022-06-29T15:50:18Z")

</div>

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?

- [GitHub - luxonis/depthai: DepthAI Python API utilities, examples, and tutorials.](https://github.com/luxonis/depthai)
- [GitHub - luxonis/depthai-python: DepthAI Python Library](https://github.com/luxonis/depthai-python)

---

<div class="post-metadata">

**Author:** ![priyam\_dalwadi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/priyam_dalwadi/32/480_2.png) [@priyam\_dalwadi](https://discuss.roboflow.com/u/priyam_dalwadi)\
**Post date:** [June 29, 2022, 3:59pm UTC](https://discuss.roboflow.com/t/error-while-running-python-file/616/8 "2022-06-29T15:59:06Z")

</div>

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](http://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](http://api.roboflow.com), and can your device download files from google cloud storage? have you hit your device limit?

---

<div class="post-metadata">

**Author:** ![priyam\_dalwadi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/priyam_dalwadi/32/480_2.png) [@priyam\_dalwadi](https://discuss.roboflow.com/u/priyam_dalwadi)\
**Post date:** [June 29, 2022, 4:17pm UTC](https://discuss.roboflow.com/t/error-while-running-python-file/616/9 "2022-06-29T16:17:21Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Mohamed](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/mohamed/32/62_2.png) [@Mohamed](https://discuss.roboflow.com/u/Mohamed)\
**Post date:** [June 29, 2022, 5:09pm UTC](https://discuss.roboflow.com/t/error-while-running-python-file/616/10 "2022-06-29T17:09:11Z")

</div>

> [@priyam\_dalwadi](#):
>
> 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:

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/a9b5f8753d680e7ddd89d032a88192f0a1f39497.jpeg)

Just remember to update the `version=1` to `version=2` if you want to test the same model.
