# OpenVINO guide ###### tags: `Intel-Movidius` ## Install Environment and device * Install OpenVINO on linux [link](https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_linux.html) * Install Movidious on linux [link](https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_linux_ivad_vpu.html) ## Setup environment variable ``` source /opt/intel/openvino/bin/setupvars.sh ``` ## API reference [api link](https://docs.openvinotoolkit.org/latest/annotated.html) ## How to use 1. Download Model ``` cd /opt/intel/openvino/deployment_tools/tools/model_downloader sudo python3 downloader.py --name mobilenet-v1-1.0-224 ``` Other avaliable models, [see here](https://github.com/opencv/open_model_zoo/tree/master/models/public) Other available pretrained models, [see here](https://github.com/opencv/open_model_zoo/tree/master/models/intel) 2. Optimize [Official guide](https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_convert_model_Converting_Model.html) ``` cd /opt/intel/openvino/deployment_tools/tools/model_downloader/ sudo -E python3 converter.py --name mobilenet-v1-1.0-224 ``` Sudo runs with different environment. To keep current environment use -E flag. Without doing this, env variable ```$INTEL_OPENVINO_DIR``` cannot be reconized. 3. Deploy ```SHELL=1 import cv2 import numpy as np from openvino.inference_engine import IENetwork, IECore path = "/opt/intel/openvino_2020.2.120/deployment_tools/open_model_zoo/tools/downloader/public/mobilenet-v1-1.0-224/FP16/" ie = IECore() # Load CPU extenstion net = ie.read_network(model=path+'mobilenet-v1-1.0-224.xml', weights=path+'mobilenet-v1-1.0-224.bin') # Read IR model input_blob = next(iter(net.inputs)) # Get input name out_blob = next(iter(net.outputs)) # Get output name batch,channel,height,width = net.inputs[input_blob].shape # Get input shape image = cv2.imread('car.jpg') cv2.imshow("input", image) # Read image and manipulate image = cv2.resize(image, (width, height)) image = image.transpose((2, 0, 1)) # Change data layout from HWC to CHW exec_net = ie.load_network(network=net, device_name='GPU') # Load IR model to device """Infer!!!""" res = exec_net.infer(inputs={input_blob: image}) idx = np.argsort(np.squeeze(res[out_blob][0]))[::-1] for i in range(5): # Display result print(idx[i]+1, res[out_blob][0][idx[i]]) cv2.waitKey(3*1000) ``` #### How to choose device? Change device names to *CPU*, *GPU* or *MYRIAD* ```SHELL=16 exec_net = ie.load_network(network=net, device_name='GPU') ``` ## FAQ 1. **"RuntimeError: Can not init Myriad device: NC_ERROR"?** sol: Maybe you should run in sudo mode, else please refer to question 4. 2. **Regarding to (1), why I get "ModuleNotFoundError: No module named 'CV2'" after running in sudo mode?** sol: This is because OpenVINO has its own optimized OpenCV and the path is set when running ```setupvars.sh```. However, the path will be reset when you are running in sudo mode. 3. **Regarding to (1) and (2), so sudo or not sudo?** sol: sudo Below is a simple workaround if you don't want to permanently disable path reset. ```SHELL=1 sudo -E su source /opt/intel/openvino/bin/setupvars.sh ...run your program ``` 4. **"RuntimeError: Can not init Myriad device: NC_ERROR" when inference on multiple model with single Myriad?** sol: Check if you are using only one IECore instance. If not, please load the networks with identical IECore instance. 5.