def _load_models(self, xmlModels, noReq, verbose): """Create an OpenVino plugin and load the .xml models onto the NCS device Arguments: xmlModels {list(str)} -- list of OpenVino XML models noReq {int} -- the number of request per network verbose {bool} -- verbose NCS device """ # Plugin initialization for specified device and load extensions library if self.mode == 'MYRIAD': self.plugin = IEPlugin(device='GPU') if verbose: self.plugin.set_config({"VPU_LOG_LEVEL": "LOG_DEBUG"}) elif self.mode == 'CPU': self.plugin = IEPlugin(device='CPU') elif self.mode == 'GPU': self.plugin = IEPlugin(device='GPU') for xmlModel in xmlModels: modelBin = os.path.splitext(xmlModel)[0] + ".bin" net = IENetwork(model=xmlModel, weights=modelBin) print('loaded', net) self.nets.append(net) self.execNets.append( self.plugin.load(network=net, num_requests=self.noReq))
def __initReidentification(self): """ Initialisierung aller Variablen, die für die Gesichtsreidentifikation benötigt werden. Vorallem wird hier die Inference Engine von OpenVINO initialisiert. """ if self.__path_to_camera == '0': self.__cap = cv2.VideoCapture(0) else: self.__cap = cv2.VideoCapture(self.__path_to_camera) net = IENetwork(model=self.__model_xml, weights=self.__model_bin) net_reid = IENetwork(model=self.__model_reid_xml, weights=self.__model_reid_bin) plugin = IEPlugin(device="CPU") plugin.add_cpu_extension(self.__path_to_cpuextension) plugin_reid = IEPlugin(device="CPU") plugin_reid.add_cpu_extension(self.__path_to_cpuextension) # plugin_reid.set_config(net_reid) self.__exec_net = plugin.load(network=net, num_requests=1) self.__exec_net_reid = plugin_reid.load(network=net_reid, num_requests=1) self.__input_blob = next(iter(net.inputs)) self.__out_blob = next(iter(net.outputs)) # print('network.inputs = ' + str(list(net.inputs))) # print('network.outputs = ' + str(list(net.outputs))) self.__model_n, self.__model_c, self.__model_h, self.__model_w = net.inputs[ self.__input_blob].shape self.__input_blob_reid = next(iter(net_reid.inputs)) self.__out_blob_reid = next(iter(net_reid.outputs)) self.__model_reid_n, self.__model_reid_c, self.__model_reid_h, self.__model_reid_w = net_reid.inputs[ self.__input_blob_reid].shape
def __init__(self): if platform.system() == 'Windows': model_xml = "./extension/IR/FP32/face-reidentification-retail-0095.xml" model_bin = "./extension/IR/FP32/face-reidentification-retail-0095.bin" self.plugin = IEPlugin(device='CPU', plugin_dirs=None) extension_path = 'extension/cpu_extension.dll' elif platform.system() == 'Darwin': model_xml = "./extension/IR/FP32/face-reidentification-retail-0095.xml" model_bin = "./extension/IR/FP32/face-reidentification-retail-0095.bin" self.plugin = IEPlugin(device='CPU', plugin_dirs=None) extension_path = 'extension/libcpu_extension.dylib' else: model_xml = "./extension/IR/FP16/face-reidentification-retail-0095.xml" model_bin = "./extension/IR/FP16/face-reidentification-retail-0095.bin" self.plugin = IEPlugin(device='MYRIAD', plugin_dirs=None) extension_path = 'extension/libcpu_extension.dylib' extension_path = pathlib.Path(extension_path) ab_extension_path = str(extension_path.resolve()) self.cpu_extension = ab_extension_path net = IENetwork(model=model_xml, weights=model_bin) self.input_blob = next(iter(net.inputs)) self.out_blob = next(iter(net.outputs)) self.n, self.c, self.h, self.w = net.inputs[self.input_blob].shape self.plugin.add_cpu_extension(self.cpu_extension) self.exec_net = self.plugin.load(network=net, num_requests=2)
def build_executors(xml_file, bin_file, devices): threads_list = [] image = cv2.imread("images/road.jpeg") dst_shape = (896, 512) input_images = cv2.dnn.blobFromImages([image], 1, dst_shape, swapRB=True) input_images_dict = {"data": input_images} for device in devices: if device == "CPU": plugin = IEPlugin(device) requests_num = benchmark_config["cpu_request_num"] config = {"CPU_THREADS_NUM": "0", "CPU_THROUGHPUT_STREAMS": str(requests_num)} plugin.add_cpu_extension(path_to_cpu_extention) elif device == "MYRIAD": plugin = IEPlugin("HDDL") config = {"LOG_LEVEL": "LOG_INFO", "VPU_LOG_LEVEL": "LOG_INFO"} requests_num = benchmark_config["myriad_request_num"] else: raise ValueError('Unidentified device "{}"!'.format(device)) sys.exit(-1) plugin.set_config(config) ie_network = IENetwork(xml_file, bin_file) exe_network = plugin.load(ie_network, requests_num) infer_executor = InferExecutor(exe_network, input_images_dict) executor_thread = InferExecutorThread(device, infer_executor, running_time) threads_list.append(executor_thread) return threads_list
def prepare_inference_engine(): """Takes and reads IR(.xml+.bin) from command line,loads device to plugin, initializes input and output blobs, and loads the network to the plugin. Returns: pointers to the loaded network, input of the network, and output of the network """ plugin = IEPlugin(device=FLAGS.d, plugin_dirs=FLAGS.plugin_dirs) model_xml = FLAGS.m model_bin = os.path.splitext(model_xml)[0] + ".bin" net = IENetwork(model=model_xml, weights=model_bin) input_blob = next(iter(net.inputs)) # grap inputs shape and dimensions output_blob = next(iter(net.outputs)) # grab output shape and dimension plugin = IEPlugin(device=FLAGS.d, plugin_dirs=None) net.batch_size = 1 #hardcoding to 1 for now exec_net = plugin.load(network=net) return exec_net, input_blob, output_blob
def load_model(self, model, device, cpu_extension=DEFAULT_CPU_EXTENSION_LINUX): ''' Load the model given IR files. Defaults to CPU as device for use in the workspace. Synchronous requests made within. ''' ### Load the model ### model_xml = model model_bin = os.path.splitext(model_xml)[0] + ".bin" # Initialize the plugin if device: plugin = IEPlugin(device) else: plugin = IEPlugin(device="CPU") # Read the IR as a IENetwork self.network = IENetwork(model=model_xml, weights=model_bin) ### Check for supported layers ### supported_layers = plugin.get_supported_layers(self.network) needed_layers = self.network.layers.keys() unsupported_layers = set(needed_layers) - set(supported_layers) self.core = IECore() ### Add any necessary extensions ### if len(unsupported_layers) > 0: if cpu_extension and device and "CPU" in device: self.core.add_extension(cpu_extension, device) else: print( "Error : there's unsupported layers in this model. Please use the -d argument and specify a supporting device" ) print('Unsupported_layers: ', unsupported_layers) sys.exit(1) # Load the IENetwork into the plugin self.exec_network = self.core.load_network(self.network, device) # Get the input layer self.input_blob = next(iter(self.network.inputs)) self.output_blob = next(iter(self.network.outputs)) ### Return the loaded inference plugin ### return self.core
def main(image, model): model_xml = cnn_models.pose_face_rec_model_xml(model) model_bin = cnn_models.pose_face_rec_model_bin(model) # Plugin initialization for specified device and load extensions library if specified plugin = IEPlugin(device='CPU', plugin_dirs=None) # Read IR net = IENetwork(model=model_xml, weights=model_bin) input_blob = next(iter(net.inputs)) out_blob = next(iter(net.outputs)) exec_net = plugin.load(network=net, num_requests=2) # Read and pre-process input image n, c, h, w = net.inputs[input_blob].shape del net in_frame = cv2.resize(image, (w, h)) in_frame = in_frame.transpose( (2, 0, 1)) # Change data layout from HWC to CHW in_frame = in_frame.reshape((n, c, h, w)) exec_net.start_async(request_id=0, inputs={input_blob: in_frame}) # Parse detection results of the current request if exec_net.requests[0].wait(-1) == 0: res = exec_net.requests[0].outputs # print('r:%f\ty:%f\tp%f' % (res['angle_r_fc'][0][0], res['angle_y_fc'][0][0], res['angle_p_fc'][0][0])) return res['angle_r_fc'][0][0], res['angle_y_fc'][0][0], res['angle_p_fc'][ 0][0]
def __init__(self, checkpoint_filename, input_name="images", output_name="features", openvino_device=None): self.openvino_device = openvino_device if openvino_device is not None: # setup device model_base = os.path.splitext(checkpoint_filename)[0] self._net = IENetwork(model=model_base + '.xml', weights=model_base + '.bin') self._plugin = IEPlugin(device=openvino_device) self._input_blob = next(iter(self._net.inputs)) self._out_blob = next(iter(self._net.outputs)) self._reload_openvino_net(1) self.session = tf.Session() with tf.gfile.GFile(checkpoint_filename, "rb") as file_handle: graph_def = tf.GraphDef() graph_def.ParseFromString(file_handle.read()) tf.import_graph_def(graph_def, name="net") self.input_var = tf.get_default_graph().get_tensor_by_name("net/%s:0" % input_name) self.output_var = tf.get_default_graph().get_tensor_by_name( "net/%s:0" % output_name) assert len(self.output_var.get_shape()) == 2 assert len(self.input_var.get_shape()) == 4 self.feature_dim = self.output_var.get_shape().as_list()[-1] self.image_shape = self.input_var.get_shape().as_list()[1:]
def load_model(device, model_xml, model_bin): plugin = IEPlugin(device=device, plugin_dirs=None) net = IENetwork(model=model_xml, weights=model_bin) exec_net = plugin.load(network=net) input_blob = next(iter(net.inputs)) output_blob = next(iter(net.outputs)) return exec_net, input_blob, output_blob
def test_device_attr(device): with warnings.catch_warnings(record=True) as w: plugin = IEPlugin(device, None) assert plugin.device == device assert len(w) == 1 assert "IEPlugin class is deprecated. " \ "Please use IECore class instead." in str(w[0].message)
def __init__(self, cameras, prepped_frame_queue): threading.Thread.__init__(self) self.cameras = cameras self.prepped_frame_queue = prepped_frame_queue # Load the edgetpu engine and labels #self.engine = DetectionEngine(PATH_TO_CKPT) #self.labels = ReadLabelFile(PATH_TO_LABELS) model_xml = PATH_TO_MODEL_XML model_bin = PATH_TO_MODEL_BIN labels = PATH_TO_MODEL_LABELS # Plugin initialization for specified device and load extensions library if specified self.plugin = IEPlugin(device='MYRIAD', plugin_dirs=None) self.net = IENetwork(model=model_xml, weights=model_bin) assert len(self.net.inputs.keys()) == 1, "Demo supports only single input topologies" assert len(self.net.outputs) == 1, "Demo supports only single output topologies" self.input_blob = next(iter(self.net.inputs)) self.out_blob = next(iter(self.net.outputs)) self.exec_net = self.plugin.load(network=self.net, num_requests=2) self.n, self.c, self.h, self.w = self.net.inputs[self.input_blob].shape #print(self.n,self.c,self.h,self.w) del self.net with open(labels, 'r') as f: self.labels_map = [x.strip() for x in f] self.next_request_id = 1 self.cur_request_id = 0
def __init__(self): try: xml_path = os.environ["XML_PATH"] bin_path = os.environ["BIN_PATH"] except KeyError: print("Please set the environment variables XML_PATH, BIN_PATH") sys.exit(1) xml_local_path = GetLocalPath(xml_path) bin_local_path = GetLocalPath(bin_path) print('path object', xml_local_path) CPU_EXTENSION = os.getenv('CPU_EXTENSION', "/usr/local/lib/libcpu_extension.so") plugin = IEPlugin(device='CPU', plugin_dirs=None) if CPU_EXTENSION: plugin.add_cpu_extension(CPU_EXTENSION) net = IENetwork(model=xml_local_path, weights=bin_local_path) self.input_blob = next(iter(net.inputs)) self.out_blob = next(iter(net.outputs)) self.batch_size = net.inputs[self.input_blob].shape[0] self.inputs = net.inputs self.outputs = net.outputs self.exec_net = plugin.load(network=net, num_requests=self.batch_size)
def load_model(self): ''' TODO: You will need to complete this method. This method is for loading the model to the device specified by the user. If your model requires any Plugins, this is where you can load them. ''' model_xml = self.model_name model_bin = os.path.splitext(model_xml)[0] + ".bin" # Initialize the plugin self.plugin = IEPlugin(device=self.device) # Add a CPU extension, if applicable if self.extensions and "CPU" in self.device: self.plugin.add_cpu_extension(self.extensions) # Read the IR as a IENetwork self.network = IENetwork(model=model_xml, weights=model_bin) ### Check for any unsupported layers, and let the user ### know if anything is missing. Exit the program, if so. unsupported_layers = [l for l in self.network.layers.keys() if l not in self.plugin.get_supported_layers(self.network)] if len(unsupported_layers) != 0: print("Unsupported layers found: {}".format(unsupported_layers)) print("Check whether extensions are available to add to IECore.") exit(1) # Load the IENetwork into the plugin self.exec_network = self.plugin.load(self.network) # Get the input layer self.input_ob = next(iter(self.network.inputs)) self.output_ob = next(iter(self.network.outputs))
def main(args): pp = pprint.PrettyPrinter(indent=4) model = args.model device = args.device image_path = args.image # Loading model model_weights = model + '.bin' model_structure = model + '.xml' model = IENetwork(model_structure, model_weights) plugin = IEPlugin(device=device) # Loading network to device net = plugin.load(network=model, num_requests=1) # Get the name of the input node input_name = next(iter(model.inputs)) # Reading and Preprocessing Image input_img = np.load(image_path) input_img = input_img.reshape(1, 28, 28) # Running Inference net.requests[0].infer({input_name: input_img}) pp.pprint(net.requests[0].get_perf_counts())
def init_model(xml, bins): model_xml = xml model_bin = bins # Plugin initialization for specified device and load extensions library if specified plugin = IEPlugin(device='CPU') plugin.add_cpu_extension( 'utils/libcpu_extension_sse4.so') log.info("Reading IR...") net = IENetwork(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 demo's command line parameters using -l " "or --cpu_extension command line argument") sys.exit(1) input_blob = next(iter(net.inputs)) out_blob = next(iter(net.outputs)) log.info("Loading IR to the plugin...") exec_nets = plugin.load(network=net, num_requests=2) n, c, h, w = net.inputs[input_blob].shape del net return exec_nets, n, c, w, h, input_blob, out_blob, plugin
def __init__(self, devid, frameBuffer, results, camera_mode, camera_width, camera_height, number_of_ncs, vidfps, skpfrm): self.devid = devid self.frameBuffer = frameBuffer self.model_xml = "./lrmodel/MobileNetSSD/MobileNetSSD_deploy.xml" self.model_bin = "./lrmodel/MobileNetSSD/MobileNetSSD_deploy.bin" self.camera_width = camera_width self.camera_height = camera_height self.num_requests = 4 self.inferred_request = [0] * self.num_requests self.heap_request = [] self.inferred_cnt = 0 self.plugin = IEPlugin(device="MYRIAD") self.net = IENetwork(model=self.model_xml, weights=self.model_bin) self.input_blob = next(iter(self.net.inputs)) self.exec_net = self.plugin.load(network=self.net, num_requests=self.num_requests) self.results = results self.camera_mode = camera_mode self.number_of_ncs = number_of_ncs if self.camera_mode == 0: self.skip_frame = skpfrm else: self.skip_frame = 0 self.roop_frame = 0 self.vidfps = vidfps
def load_network(model_full_path, device, extensions, batch=1, new_shape=None): from openvino.inference_engine import IENetwork, IEPlugin # Read in Graph file (IR) net = IENetwork.from_ir(model=model_full_path + ".xml", weights=model_full_path + ".bin") input_blob = next(iter(net.inputs)) out_blob = next(iter(net.outputs)) # Plugin initialization for specified device and load extensions library if needed plugin = IEPlugin(device=device.upper()) if 'extension library' in extensions[device]: plugin.add_cpu_extension(extensions[device]['extension library']) if device.upper() == 'MYRIAD': # TODO: set to true if you want to use multiple NCS devices # plugin.set_config({"VPU_FORCE_RESET": "YES"}) exec_net = plugin.load(network=net) else: net.batch_size = batch exec_net = plugin.load(network=net) # exec_net = plugin.load(network=net, config={'DYN_BATCH_ENABLED': 'YES'}) del net return plugin, exec_net, input_blob, out_blob
def test_init_plugin(device): with warnings.catch_warnings(record=True) as w: plugin = IEPlugin(device, None) assert isinstance(plugin, IEPlugin) assert len(w) == 1 assert "IEPlugin class is deprecated. " \ "Please use IECore class instead." in str(w[0].message)
def test_set_config(device): with warnings.catch_warnings(record=True) as w: plugin = IEPlugin("HETERO:CPU") plugin.set_config({"TARGET_FALLBACK": "CPU,GPU"}) assert len(w) == 1 assert "IEPlugin class is deprecated. " \ "Please use IECore class instead." in str(w[0].message)
def test_get_version(device): with warnings.catch_warnings(record=True) as w: plugin = IEPlugin(device, None) assert not len(plugin.version) == 0 assert len(w) == 1 assert "IEPlugin class is deprecated. " \ "Please use IECore class instead." in str(w[0].message)
def __init__(self, devid, frameBuffer, results, camera_width, camera_height, number_of_ncs, vidfps): self.devid = devid self.frameBuffer = frameBuffer self.model_xml = "./lrmodels/tiny-YoloV3/FP16/frozen_tiny_yolo_v3.xml" self.model_bin = "./lrmodels/tiny-YoloV3/FP16/frozen_tiny_yolo_v3.bin" self.camera_width = camera_width self.camera_height = camera_height self.m_input_size = 416 self.threshould = 0.4 self.num_requests = 4 self.inferred_request = [0] * self.num_requests self.heap_request = [] self.inferred_cnt = 0 self.plugin = IEPlugin(device="MYRIAD") self.net = IENetwork(model=self.model_xml, weights=self.model_bin) self.input_blob = next(iter(self.net.inputs)) self.exec_net = self.plugin.load(network=self.net, num_requests=self.num_requests) self.results = results self.number_of_ncs = number_of_ncs self.predict_async_time = 800 self.skip_frame = 0 self.roop_frame = 0 self.vidfps = vidfps self.new_w = int(camera_width * min(self.m_input_size/camera_width, self.m_input_size/camera_height)) self.new_h = int(camera_height * min(self.m_input_size/camera_width, self.m_input_size/camera_height))
def load_model(self): ''' TODO: You will need to complete this method. This method is for loading the model to the device specified by the user. If your model requires any Plugins, this is where you can load them. ''' if self.device == 'GPU': self.ie = IECore() self.model = IENetwork(model = self.xml, weights = self.bin) supported_layers = self.ie.query_network(self.model, self.device) supported_layers.update(self.ie.query_network(self.model, 'CPU')) self.net = self.ie.load_network(self.model, self.device) self.plugin = IEPlugin(device = self.device) self.model = IENetwork(model = self.xml, weights = self.bin) t0 = time.time() self.net = self.plugin.load(self.model) t1 = time.time() print('Face Detection Load time = ', (t1-t0)) self.input_name = next(iter(self.model.inputs)) self.input_shape = self.model.inputs[self.input_name].shape self.output_name = next(iter(self.model.outputs)) self.output_shape = self.model.outputs[self.output_name].shape self.check_model()
def main(): global start_time image_queue = queue.Queue(maxsize=4) model_dir = os.environ[ 'HOME'] + "/model_downloader/object_detection/common/mobilenet-ssd/caffe/FP16/" model_xml = model_dir + "mobilenet-ssd.xml" model_bin = model_dir + "mobilenet-ssd.bin" plugin = IEPlugin(device="MYRIAD") net = IENetwork(model=model_xml, weights=model_bin) input_blob = next(iter(net.inputs)) out_blob = next(iter(net.outputs)) n, c, h, w = net.inputs[input_blob].shape exec_net = plugin.load(network=net, num_requests=2) start_time = time.time() preprocess_thread = None preprocess_thread = threading.Thread(target=image_process_worker, args=(image_queue, n, c, h, w)) preprocess_thread.start() async_infer_worker(exec_net, image_queue, input_blob, out_blob) preprocess_thread.join() print() del exec_net del net del plugin
def __init__(self, device, getFrameFunc): self.getFrameFunc = getFrameFunc self.originFrame = None self.newDataAvailable = False if device == 'CPU': model_xml = './models/FP32/mobilenet-ssd.xml' else: model_xml = './models/FP16/mobilenet-ssd.xml' model_bin = os.path.splitext(model_xml)[0] + ".bin" cpu_extension = '/opt/intel/openvino/inference_engine/lib/intel64/libcpu_extension_sse4.so' self.labels = ["None", "plane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "table", "dog", "horse", "motorcycle", "person", "plant", "sheep", "sofa", "train", "monitor"] net = IENetwork(model=model_xml, weights=model_bin) plugin = IEPlugin(device=device) if cpu_extension and 'CPU' in device: plugin.add_cpu_extension(cpu_extension) self.exec_net = plugin.load(net) self.input_blob = next(iter(net.inputs)) self.out_blob = next(iter(net.outputs)) n, c, self.h, self.w = net.inputs[self.input_blob].shape self.detectedObjects = [] self.infer_time = 0 self.inferFPS = 15 processThread = threading.Thread(target=self.inferenceThread) processThread.daemon = True processThread.start()
def main(args): model = args.model device = args.device image_path = args.image # Loading model model_weights = model + '.bin' model_structure = model + '.xml' model = IENetwork(model_structure, model_weights) plugin = IEPlugin(device=device) # Loading network to device net = plugin.load(network=model, num_requests=1) # Get the name of the input node input_name = next(iter(model.inputs)) # Reading and Preprocessing Image image = cv2.imread(image_path) resized_img = cv2.resize(image, (544, 320)) input_img = np.moveaxis(resized_img, -1, 0) # Running Inference in a loop on the same image for _ in range(int(args.iterations)): net.infer({input_name: input_img})
def IEsetup(model_xml, model_bin, device, verbose=False): start = time() plugin = IEPlugin(device=device, plugin_dirs=None) libcpu = "inference_engine_samples/intel64/Release/lib/libcpu_extension.so" libcpu = os.environ['HOME'] + "/" + libcpu if device == "CPU": plugin.add_cpu_extension(libcpu) net = IENetwork(model=model_xml, weights=model_bin) if verbose: print("* IEsetup", model_bin, "on", device) exec_net = plugin.load(network=net, num_requests=1) input_blob = next(iter(net.inputs)) #input_blob = 'data' model_n, model_c, model_h, model_w = net.inputs[input_blob].shape if verbose: print("network in shape n/c/h/w (from xml)= %d %d %d %d" % (model_n, model_c, model_h, model_w)) if verbose: print("input_blob =", input_blob) out_blobs = [] for out_blob in net.outputs: if verbose: print(" net.outputs[", out_blob, "].shape", net.outputs[out_blob].shape) out_blobs.append(out_blob) if verbose: print("* IEsetup done %.2fmsec" % (1000. * (time() - start))) del net return exec_net, plugin, input_blob, out_blobs
def load_ir_model(model_xml, device, plugin_dir, cpu_extension): model_bin = os.path.splitext(model_xml)[0] + ".bin" # initialize plugin log.info("Initializing plugin for %s device...", device) plugin = IEPlugin(device=device, plugin_dirs=plugin_dir) if cpu_extension and 'CPU' in device: plugin.add_cpu_extension(cpu_extension) # read IR net = IENetwork(model=model_xml, weights=model_bin) if "CPU" in device: supported_layers = plugin.get_supported_layers(net) not_supported_layers = [ l for l in net.layers.keys() if l not in supported_layers ] if not_supported_layers: log.error( "Following layers are not supported by the plugin for specified device %s:\n %s", plugin.device, ', '.join(not_supported_layers)) log.error( "Please try to specify cpu extensions library path in sample's command line parameters using " "--cpu_extension command line argument") sys.exit(1) input_blob = next(iter(net.inputs)) out_blob = next(iter(net.outputs)) exec_net = plugin.load(network=net, num_requests=2) shape = net.inputs[input_blob].shape # pylint: disable=E1136 del net return exec_net, plugin, input_blob, out_blob, shape
def load_ie_model(model_xml, device, plugin_dir, cpu_extension=''): """Loads a model in the Inference Engine format""" model_bin = os.path.splitext(model_xml)[0] + ".bin" # Plugin initialization for specified device and load extensions library if specified plugin = IEPlugin(device=device, plugin_dirs=plugin_dir) if cpu_extension and 'CPU' in device: plugin.add_cpu_extension(cpu_extension) # Read IR log.info("Loading network files:\n\t%s\n\t%s", model_xml, model_bin) net = IENetwork(model=model_xml, weights=model_bin) if "CPU" in plugin.device: supported_layers = plugin.get_supported_layers(net) not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers] if not_supported_layers: log.error("Following layers are not supported by the plugin for specified device %s:\n %s", 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, "Checker supports only single input topologies" assert len(net.outputs) == 1, "Checker 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 = 1 # Loading model to the plugin log.info("Loading model to the plugin") exec_net = plugin.load(network=net) model = IEModel(exec_net, net.inputs, input_blob, out_blob) del net return model
def __init__(self, model_bin, model_xml, device): log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout) # Plugin initialization for specified device and load extensions library if specified log.info("Initializing plugin for {} device...".format(device)) self.plugin = IEPlugin(device=device) # Read IR log.info("Reading IR...") net = IENetwork(model=model_xml, weights=model_bin) cpu_extension = "/usr/local/lib/libcpu_extension.so" if cpu_extension and 'CPU' in device: self.plugin.add_cpu_extension(cpu_extension) assert len(net.inputs.keys( )) == 1, "This application supports only single input topologies" assert len( net.outputs) == 1, "This application supports only single output topologies" self.input_blob = next(iter(net.inputs)) self.out_blob = next(iter(net.outputs)) log.info("Loading IR to the plugin...") self.exec_net = self.plugin.load(network=net, num_requests=2) self.n, self.c, self.h, self.w = net.inputs[self.input_blob].shape del net self.asynchronous = False self.cur_request_id = 0 self.next_request_id = 1
def ArrangeNetwork(self): log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout) # Plugin initialization for specified device and load extensions library if specified plugin = IEPlugin(device=self.device) if self.cpu_extension and 'CPU' in self.device: plugin.add_cpu_extension(self.cpu_extension) # Read IR net = IENetwork.from_ir(model=self.model_xml, weights=self.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" self.input_blob = next(iter(net.inputs)) # Set input size self.input_size = net.inputs[self.input_blob].shape[2:] # Load network to the plugin self.exec_net = plugin.load(network=net) del net # Warmup with last image to avoid caching self.exec_net.infer( inputs={ self.input_blob: np.zeros((1, 3, self.input_size[0], self.input_size[1])) })