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.

Inference Engine Python API Error

Jorge_García_Martíne
3,195 Views

Hello everybody,

when I try to execute the Inference Engine python API with "HETERO:FPGA,CPU" device I have the following error:

    exec_net = ie.load_network(network=net, device_name=args.device)
    File "ie_api.pyx", line 85, in openvino.inference_engine.ie_api.IECore.load_network
    File "ie_api.pyx", line 92, in openvino.inference_engine.ie_api.IECore.load_network
    RuntimeError: Failed to call QueryNetwork for FPGA device, error: Failed to create FPGA device handle with ID 0

 

In CPU the example is OK and when I execute the demos (demo_security_barrier_camera.sh and demo_squeezenet_download_convert_run.sh) with HETERO:FPGA,CPU is OK too.

The FPGA diagnose device is OK.

Any help is welcome!

Thanks...


 

0 Kudos
9 Replies
Sahira_Intel
Moderator
3,195 Views

Hi Jorge,

What was the command you used to deploy your model? Can you please give more information about your model?

Best Regards,

Sahira 

0 Kudos
Jorge_García_Martíne
3,195 Views

Hello, I have developed the following model:

 

Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_3 (Conv2D)            (None, 24, 24, 32)        832       
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 12, 12, 32)        0         
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 8, 8, 64)          51264     
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 4, 4, 64)          0         
_________________________________________________________________
flatten_2 (Flatten)          (None, 1024)              0         
_________________________________________________________________
dense_2 (Dense)              (None, 10)                10250  

  • I've run the model optimizer for FP16 precision.
  • The code for Inference Engine tool with HETERO:FPGA,CPU is (similar to classification_sample.py):
    #!/usr/bin/env python
    """
     Copyright (C) 2018-2019 Intel Corporation
    
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
    
          http://www.apache.org/licenses/LICENSE-2.0
    
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
    """
    from __future__ import print_function
    import sys
    import os
    from argparse import ArgumentParser, SUPPRESS
    import cv2
    import numpy as np
    import logging as log
    from time import time
    from openvino.inference_engine import IENetwork, IECore
    
    
    def build_argparser():
        parser = ArgumentParser(add_help=False)
        args = parser.add_argument_group('Options')
        args.add_argument('-h', '--help', action='help', default=SUPPRESS, help='Show this help message and exit.')
        args.add_argument("-m", "--model", help="Required. Path to an .xml file with a trained model.", required=True,
                          type=str)
        args.add_argument("-i", "--input", help="Required. Path to a folder with images or path to an image files",
                          required=True,
                          type=str, nargs="+")
        args.add_argument("-l", "--cpu_extension",
                          help="Optional. Required for CPU custom layers. "
                               "MKLDNN (CPU)-targeted custom layers. Absolute path to a shared library with the"
                               " kernels implementations.", type=str, default=None)
        args.add_argument("-d", "--device",
                          help="Optional. Specify the target device to infer on; CPU, GPU, FPGA, HDDL, MYRIAD or HETERO: is "
                               "acceptable. The sample will look for a suitable plugin for device specified. Default "
                               "value is CPU",
                          default="CPU", type=str)
        args.add_argument("--labels", help="Optional. Path to a labels mapping file", default=None, type=str)
        args.add_argument("-nt", "--number_top", help="Optional. Number of top results", default=10, type=int)
    
        return parser
    
    
    def main():
        log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
        args = build_argparser().parse_args()
        model_xml = args.model
        model_bin = os.path.splitext(model_xml)[0] + ".bin"
    
        # Plugin initialization for specified device and load extensions library if specified
        log.info("Creating Inference Engine")
        ie = IECore()
        if args.cpu_extension and 'CPU' in args.device:
            ie.add_extension(args.cpu_extension, "CPU")
    
    
        # Read IR
        log.info("Loading network files:\n\t{}\n\t{}".format(model_xml, model_bin))
        net = IENetwork(model=model_xml, weights=model_bin)
    
        if "CPU" in args.device:
            supported_layers = ie.query_network(net, "CPU")
            not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers]
            if len(not_supported_layers) != 0:
                log.error("Following layers are not supported by the plugin for specified device {}:\n {}".
                          format(args.device, ', '.join(not_supported_layers)))
                log.error("Please try to specify cpu extensions library path in sample's command line parameters using -l "
                          "or --cpu_extension command line argument")
                sys.exit(1)
    
        assert len(net.inputs.keys()) == 1, "Sample supports only single input topologies"
        assert len(net.outputs) == 1, "Sample supports only single output topologies"
    
        log.info("Preparing input blobs")
        input_blob = next(iter(net.inputs))
        out_blob = next(iter(net.outputs))
        net.batch_size = len(args.input)
        print("PARAMETROS RED")
        print("net.imputs: ", input_blob)
        print("net.outputs: ", out_blob)
        print("batch_size: ", net.batch_size)
    
        # Read and pre-process input images
        n, c, h, w = net.inputs[input_blob].shape
        images = np.ndarray(shape=(n, c, h, w))
        print("Valor de n: ", n)
        print("Valor de c: ", c)
        print("Valor de h: ", h)
        print("Valor de w: ", w)
        print("Images", images.shape)
    
        for i in range(n):
            image = cv2.imread(args.input)
            if image.shape[:-1] != (h, w):
                log.warning("Image {} is resized from {} to {}".format(args.input, image.shape[:-1], (h, w)))
                image = cv2.resize(image, (w, h))
            image = image.transpose((2, 0, 1))  # Change data layout from HWC to CHW
            images = image[2,:,:]
        log.info("Batch size is {}".format(n))
    
    
        # Loading model to the plugin
        log.info("Loading model to the plugin")
        exec_net = ie.load_network(network=net, device_name=args.device)
    
        # Start sync inference
        log.info("Starting inference in synchronous mode")
        res = exec_net.infer(inputs={input_blob: images})
    
        # Processing output blob
        log.info("Processing output blob")
        res = res[out_blob]
        log.info("Top {} results: ".format(args.number_top))
        if args.labels:
            with open(args.labels, 'r') as f:
                labels_map = [x.split(sep=' ', maxsplit=1)[-1].strip() for x in f]
        else:
            labels_map = None
        classid_str = "classid"
        probability_str = "probability"
        for i, probs in enumerate(res):
            probs = np.squeeze(probs)
            top_ind = np.argsort(probs)[-args.number_top:][::-1]
            print("Image {}\n".format(args.input))
            print(classid_str, probability_str)
            print("{} {}".format('-' * len(classid_str), '-' * len(probability_str)))
            for id in top_ind:
                det_label = labels_map[id] if labels_map else "{}".format(id)
                label_length = len(det_label)
                space_num_before = (len(classid_str) - label_length) // 2
                space_num_after = len(classid_str) - (space_num_before + label_length) + 2
                space_num_before_prob = (len(probability_str) - len(str(probs[id]))) // 2
                print("{}{}{}{}{:.7f}".format(' ' * space_num_before, det_label,
                                              ' ' * space_num_after, ' ' * space_num_before_prob,
                                              probs[id]))
            print("\n")
        log.info("This sample is an API example, for any performance measurements please use the dedicated benchmark_app tool\n")
    
    if __name__ == '__main__':
        sys.exit(main() or 0)

     

  • And the comand to run Inference Engine:

python3 cero_IE.py -m /home/cero_red_CNN/Inference_Engine_FPGA/FP16/tf_model0_fp16.xml -i /home/cero_red_CNN/Inference_Engine_FPGA/FP16/Images/cuatro.png -d HETERO:FPGA,CPU

Thanks for all. Jorge.

0 Kudos
Sahira_Intel
Moderator
3,195 Views

Hi Jorge,

When you converted your model, did you use --data_type FP16? If so, you used the conversion to run on Myriad (VPU). If you want to run on the CPU, convert your model with the parameter --data_type FP32. 

I hope this information is helpful.

Best,

Sahira 

0 Kudos
Jorge_García_Martíne
3,195 Views

Hi Sahira,

I've converted my model with FP32 and I have the same problem, the bit stream and the 'aocl diagnose'' are:

Vendor: Intel Corp

Physical Dev Name   Status            Information

pac_a10_ec00000     Passed            PAC Arria 10 Platform (pac_a10_ec00000)
                                      PCIe 59:00.0
                                      FPGA temperature = 51 degrees C.

DIAGNOSTIC_PASSED
--------------------------------------------------------------------
 

Bitstream --> /opt/intel/openvino_fpga_2019.1.144/bitstreams/a10_dcp_bitstreams/2019R1_RC_FP16_ResNet_SqueezeNet_VGG.aocx

 

 

0 Kudos
Sahira_Intel
Moderator
3,195 Views

Hi Jorge,

Can you please run the Benchmark Application with the parameter -d HETERO:FPGA,CPU? Are you getting the same errors? 

Best,

Sahira 

0 Kudos
Jorge_García_Martíne
3,195 Views

Hi Sahira,

I get the same errors. Any idea about the problem?

 

Thanks, Jorge.

0 Kudos
NSVR
Novice
2,695 Views

Did you solve this issue. I am also facing the same. Your help is highly appreciated.

0 Kudos
E-Hong
New Contributor I
2,522 Views

Hi, 

Have you solved the problem? I have the same issue on DevCloud too.

0 Kudos
Sahira_Intel
Moderator
3,195 Views

Hi Jorge,

It looks like you're using an older version of OpenVINO - can you please try upgrading to the latest version of OpenVINO? 

Best Regards,

Sahira 

 

 

0 Kudos
Reply