Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6480 Discussions

Exception has occurred: KeyError 'boxes'

RGVGreatCoder
Novice
2,108 Views

When I execute a loaded network in my Python program, it crashes with the error "Exception has occurred: KeyError 'boxes'" (I get the same error in my WSL Ubuntu and Raspberry Pi 4).  I am implementing the code in this page "https://docs.openvino.ai/latest/notebooks/004-hello-detection-with-output.html#" and, my program reads as follows:

 

import matplotlib.pyplot as plt
import numpy as np
from openvino.inference_engine import IECore
...
openvino_xml = openvino_model_path + 'person-vehicle-bike-detection-crossroad-1016.xml'
openvino_weights = openvino_model_path + 'person-vehicle-bike-detection-crossroad-1016.bin'
device_name = 'MYRIAD' # try this on the Rpi4
# device_name = 'CPU'  # try this on WSL Ubuntu runnin in my laptop
picture = picture_captured_path + 'cars-expressway1.jpg'

ie = IECore()
net = ie.read_network(
    model=openvino_xml,
    weights=openvino_weights,
)
exec_net = ie.load_network(net, device_name)
input_layer_ir = next(iter(exec_net.input_info))
output_layer_ir = next(iter(exec_net.outputs))

# get input and output names of nodes
input_key = list(exec_net.input_info)[0]
output_key = list(exec_net.outputs.keys())[0]

def printOpenVino_InputOutputItems():
   print("Inputs:")
   for name, info in exec_net.input_info.items():
      print("\tname: {}".format(name))
      print("\tshape: {}".format(info.tensor_desc.dims))
      # print("\tlayout: {}".format(info.layout))
      print("\tprecision: {}\n".format(info.precision))

   print("Outputs:")
   for name, info in exec_net.outputs.items():
      print("\tname: {}".format(name))
      print("\tshape: {}".format(info.shape))
      print("\tlayout: {}".format(info.layout))
      print("\tprecision: {}\n".format(info.precision))

   print("input_key: " + input_key)
   print("output_key: " + output_key)


# Check values in Inputs and Outputs
printOpenVino_InputOutputItems()

imageFrame = cv.imread(picture)

if (type(imageFrame) == type(None)):
   break

# Resize with OpenCV your image if needed to match with net input shape
N, C, H, W = exec_net.input_info[input_layer_ir].tensor_desc.dims
resized_image = cv.resize(src=imageFrame, dsize=(W, H))      

# Converting image to NCHW format with FP32 type
input_data = np.expand_dims(resized_image.transpose(2, 0, 1), 0)

# DO INFERENCE
result = exec_net.infer(inputs={input_layer_ir: input_data})

# Extract list of boxes from results
boxes = result["boxes"]

 

 When I run this program, it first executes the printOpenVino_InputOutputItems()  method printing these results:

 

Inputs:
        name: input.1
        shape: [1, 3, 512, 512]
        precision: FP32

Outputs:
        name: 653
        shape: [1, 1, 200, 7]
        layout: NCHW
        precision: FP32

input_key: input.1
output_key: 653
Backend QtAgg is interactive backend. Turning interactive mode on.

 

But then in line 62 of my program (where I try to extract the boxes from the results variable), I get the following error:

 

Exception has occurred: KeyError
'boxes'
  File "/home/winlinuxuser/projects/classify-vehicle/openvino-pi4-vehicle-person.py", line 62
    boxes = result["boxes"]

 

Putting a breakpoint in line 59 (using VSCode), I could read the content in the "result" variable and, it was the following one:

result-value.jpg

Questions:

  1. Why am I getting this error?
  2. How can I extract the boxes from the result variable?

Thank you in advance for all your support and will be waiting for your reply,

 

0 Kudos
5 Replies
Wan_Intel
Moderator
2,073 Views

Hi RGVGreatCoder,

Thanks for reaching out to us and thanks for sharing your information with us.

 

We are now investigating this issue and we will update you at the earliest.

 

 

Regards,

Wan


0 Kudos
Wan_Intel
Moderator
2,060 Views

Hi RGVGreatCoder,

 

I noticed that the horizontal-text-detection-0001 contains boxes as one of the Results.

horizon.JPG

 

 

while person-vehicle-bike-detection-crossroad-1016 only contains detection_out as a Result.

customer_model.JPG

 

 

You may check it by using Netron.

 

As a workaround, I suggest you use the Object Detection SSD Python Sample. The demo is located under the following directory:

<INSTALL_DIR>\inference_engine\samples\python\object_detection_sample_ssd

 

On another note, I have validated the demo application with person-vehicle-bike-detection-crossroad-1016 as shown as follows.

Capture.JPG

 

 

 

 

Regards,

Wan

 

0 Kudos
RGVGreatCoder
Novice
2,034 Views

You suggest me to look for the sample in this directory:

<INSTALL_DIR>\inference_engine\samples\python\object_detection_sample_ssd

I cannot find this directory. I installed OpenVINO toolkit using PIP. Where should I find the sample if I used PIP?

0 Kudos
Hairul_Intel
Moderator
2,018 Views

Hi RGVGreatCoder,

Yes, you are correct. OpenVINO Toolkit PIP Package does not come with the Inference Engine Samples directory.

 

You could instead, find the particular Object Detection SSD Python Sample from GitHub. Download or copy the Python Sample script and place it in your directory.

 

Since you're using the OpenVINO PIP Package, use the following command to get the necessary models for the Python sample:

omz_downloader --name mobilenet-ssd

omz_converter --name mobilenet-ssd

 

Once downloaded, run the Object Detection SSD Python Sample with the following command:

python <path_to_sample>/object_detection_sample_ssd.py -m <path_to_model>/mobilenet-ssd.xml -i <path_to_image> -d CPU

 

 

Regards,

Hairul


0 Kudos
Wan_Intel
Moderator
1,978 Views

Hi RGVGreatCoder,

This thread will no longer be monitored since we have provided a suggestion. 

 

If you need any additional information from Intel, please submit a new question.

 

 

Regards,

Wan

 

0 Kudos
Reply