How to use the openvino.inference_engine.IENetwork.from_ir function in openvino

To help you get started, we’ve selected a few openvino examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github opencv / openvino_training_extensions / training_toolbox / ssd_detector / regression_test / train_net.py View on Github external
def run_ie_on_dataset(model_xml, model_bin, cpu_extension_path, images_dir, prob_threshold=0.01):
    plugin = IEPlugin(device='CPU')
    plugin.add_cpu_extension(cpu_extension_path)
    net = IENetwork.from_ir(model=model_xml, weights=model_bin)
    assert len(net.inputs.keys()) == 1, "Sample supports only single input topologies"
    assert len(net.outputs) == 1, "Sample supports only single output topologies"
    input_blob = next(iter(net.inputs))
    out_blob = next(iter(net.outputs))
    exec_net = plugin.load(network=net, num_requests=2)
    num, chs, height, width = net.inputs[input_blob]
    del net
    cur_request_id = 0

    detection_data = []
    for image in os.listdir(images_dir):
      im_path = os.path.join(images_dir, image)
      frame = cv2.imread(im_path)
      initial_h, initial_w, _ = frame.shape
      in_frame = cv2.resize(frame, (width, height))
      in_frame = in_frame.transpose((2, 0, 1))  # Change data layout from HWC to CHW
github PINTO0309 / OpenVINO-ADAS / openvino_test_CPU.py View on Github external
#!/usr/bin/env python

import sys
import cv2
import numpy as np
from PIL import Image
import time
from openvino.inference_engine import IENetwork, IEPlugin

model_xml='lrmodels/FP32/semantic-segmentation-adas-0001.xml'
model_bin='lrmodels/FP32/semantic-segmentation-adas-0001.bin'
net = IENetwork.from_ir(model=model_xml, weights=model_bin)
seg_image = Image.open("data/input/009649.png")
palette = seg_image.getpalette() # Get a color palette
camera_width = 320
camera_height = 240
fps = ""
framepos = 0
frame_count = 0
vidfps = 0
elapsedTime = 0

#plugin = IEPlugin(device="HETERO:MYRIAD,CPU")
#plugin.set_config({"TARGET_FALLBACK": "HETERO:MYRIAD,CPU"})
#plugin.set_initial_affinity(net)

#plugin = IEPlugin(device="MYRIAD")
#plugin = IEPlugin(device="GPU")
github opencv / dldt / inference-engine / ie_bridges / python / sample / segmentation_sample.py View on Github external
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
    plugin = IEPlugin(device=args.device, plugin_dirs=args.plugin_dir)
    if args.cpu_extension and 'CPU' in args.device:
        plugin.add_cpu_extension(args.cpu_extension)
    # Read IR
    log.info("Loading network files:\n\t{}\n\t{}".format(model_xml, model_bin))
    net = IENetwork.from_ir(model=model_xml, weights=model_bin)

    if plugin.device == "CPU":
        supported_layers = plugin.get_supported_layers(net)
        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(plugin.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))
github yuanyuanli85 / Fast_Stacked_Hourglass_Network_OpenVino / src / stacked_hourglass.py View on Github external
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
    plugin = IEPlugin(device=args.device, plugin_dirs=args.plugin_dir)
    if args.cpu_extension and 'CPU' in args.device:
        plugin.add_cpu_extension(args.cpu_extension)
    # Read IR
    log.info("Loading network files:\n\t{}\n\t{}".format(model_xml, model_bin))
    net = IENetwork.from_ir(model=model_xml, weights=model_bin)

    if plugin.device == "CPU":
        supported_layers = plugin.get_supported_layers(net)
        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(plugin.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))
github DT42 / BerryNet / berrynet / engine / openvino_engine.py View on Github external
#                   for x in f]
        else:
            self.labels_map = None
        self.top_k = top_k

        # Plugin initialization for specified device and
        # load extensions library if specified
        #
        # Note: MKLDNN CPU-targeted custom layer support is not included
        #       because we do not use it yet.
        self.plugin = IEPlugin(device=device, plugin_dirs=None)

        # Read IR
        logger.debug('Loading network files:'
                     '\n\txml: {0}\n\tbin: {1}'.format(model_xml, model_bin))
        net = IENetwork.from_ir(model=model_xml, weights=model_bin)

        if self.plugin.device == "CPU":
            supported_layers = self.plugin.get_supported_layers(net)
            not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers]
            if len(not_supported_layers) != 0:
                logger.error("Following layers are not supported by the plugin for specified device {}:\n {}".format(self.plugin.device, ', '.join(not_supported_layers)))
                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"

        # input_blob and and out_blob are the layer names in string format.
        logger.debug("Preparing input blobs")
        self.input_blob = next(iter(net.inputs))
        self.out_blob = next(iter(net.outputs))
        net.batch_size = 1
github opencv / open_model_zoo / demos / python_demos / accuracy_checker / accuracy_checker / launcher / dlsdk_launcher.py View on Github external
self._device = self._config['device'].upper()
        self._prepare_bitstream_firmware(self._config)
        self.plugin = ie.IEPlugin(self._device)
        print_info('Loaded {} plugin version: {}'.format(self.plugin.device, self.plugin.version))

        if dlsdk_launcher_config.need_conversion:
            self._convert_model(self._config, dlsdk_launcher_config.framework)
        else:
            self._model = self._config['model']
            self._weights = self._config['weights']

        if self._config.get('cpu_extensions') and 'CPU' in self._device:
            self.plugin.add_cpu_extension(str(self._config.get('cpu_extensions')))
        if self._config.get('gpu_extensions') and 'GPU' in self._device:
            self.plugin.set_config('CONFIG_FILE', str(self._config.get('gpu_extensions')))
        self.network = ie.IENetwork.from_ir(model=str(self._model), weights=str(self._weights))
        self.original_outputs = self.network.outputs
        outputs = self._config.get('outputs')
        if outputs:
            self.network.add_outputs(outputs)
        self.exec_network = self.plugin.load(network=self.network)
        self._config_inputs = parse_inputs(self._config.get('inputs', []))
        check_user_inputs(self.network.inputs.keys(), self._config_inputs)
        reshape_user_inputs(self._config_inputs, self.exec_network.requests[0].inputs)
        image_inputs = list(filter(lambda input: input not in self._config_inputs, self.inputs.keys()))
        if not image_inputs:
            raise ValueError('image input is not found')
        if len(image_inputs) > 1:
            raise ValueError('topologies with several image inputs are not supported')
        self._image_input_blob = image_inputs[0]
        self._batch = self.network.inputs[self._image_input_blob].shape[0]
github opencv / cvat / datumaro / datumaro / components / launchers / openvino.py View on Github external
def make_network(model, weights):
        return IENetwork.from_ir(model=model, weights=weights)