# OpenVINO Quick Get Started on Ubuntu 20.04
###### tags: `OpenVINO` `2021.2` `Ubuntu` `20.04`
## 在 Ubuntu 20.04 電腦上安裝 OpenVINO Toolkit
- Table of Content
[ToC]
### :memo: 系統需求
硬體 :
Intel CPU 筆電/桌機/NUC 
軟體 :
Ubuntu 20.04
Intel Distribution OpenVINO Toolkit
Python 3.8.x 64-bit
### 下載 Intel® Distribution of OpenVINO™ Toolkit
https://software.intel.com/en-us/openvino-toolkit/choose-download

### 安裝 Intel® Distribution of OpenVINO™ Toolkit
Step 1: Open a command prompt terminal window.
Step 2: Unpack the .tgz file.
tar -xzf l_openvino_toolkit_p_2.185.tgz
Step 3: Go to the l_openvino_toolkit_p_2.185 directory:
cd l_openvino_toolkit_p_2.185
Step 4: Choose your installation option.
sudo ./install_GUI.sh
Step 5: Follow the instructions in the installer.






Step 6: The core components are installed. To complete the configuration, follow the instructions in the Complete Installation Guide.
### 安裝OpenVINO toolkit所需的Python套件
```
cd /opt/intel/openvino_2021/install_dependencies/
sudo ./install_openvino_dependencies.sh
source /opt/intel/openvino_2021/bin/setupvars.sh
cd /opt/intel/openvino_2021/deployment_tools/model_optimizer/install_prerequisites
./install_prerequisites_tf2.sh
./install_prerequisites_onnx.sh
cd /opt/intel/openvino_2021/deployment_tools/tools/model_downloader/
pip3 install -r requirements.in
```
### 安裝OpenVINO toolkit所需的Python套件 : 使用virtualenv (建議使用,非必須)
```
cd /opt/intel/openvino_2021/install_dependencies/
sudo ./install_openvino_dependencies.sh
sudo -E apt -y --no-install-recommends install python3-pip python3-venv
sudo -E python3 -m pip install --upgrade pip
python3 -m venv ~/ov_venv
source ~/ov_venv/bin/activate
source /opt/intel/openvino_2021/bin/setupvars.sh
pip3 install -r /opt/intel/openvino_2021/deployment_tools/model_optimizer/requirements_tf2.txt
pip3 install -r /opt/intel/openvino_2021/deployment_tools/model_optimizer/requirements_onnx.txt
pip3 install -r /opt/intel/openvino_2021/deployment_tools/tools/model_downloader/requirements.in
````
### 使用OpenVINO Toolkit做影像辨識
使用神經網路模型執行影像辨識只要三個步驟
1. 取得神經網路模型
1. 對神經網路模型進行推論優化
1. 執行影像辨識推論 (在Intel CPU, Intel GPU以及VPU)
### 步驟1 取得神經網路模型

```
cd
python3 /opt/intel/openvino_2021/deployment_tools/tools/model_downloader/downloader.py --name mobilenet-v2-1.0-224
```
### 步驟2 對神經網路模型進行推論優化

```
cd
python3 /opt/intel/openvino_2021/deployment_tools/tools/model_downloader/converter.py --name mobilenet-v2-1.0-224
```
### 步驟3 執行影像辨識推論 (18 lines of Python code)

```
cd
cp ~/public/mobilenet-v2-1.0-224/FP16/mobilenet-v2-1.0-224.xml .
cp ~/public/mobilenet-v2-1.0-224/FP16/mobilenet-v2-1.0-224.bin .
cp /opt/intel/openvino_2021/deployment_tools/demo/car.png .
python3
```
```python=
import cv2
import numpy as np
from openvino.inference_engine import IENetwork, IECore
ie = IECore()
net = ie.read_network(model='mobilenet-v2-1.0-224.xml')
input_blob = next(iter(net.inputs))
out_blob = next(iter(net.outputs))
batch,channel,height,width = net.inputs[input_blob].shape
image = cv2.imread('car.png')
cv2.imshow("input", image)
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='CPU')
res = exec_net.infer(inputs={input_blob: image})
idx = np.argsort(np.squeeze(res[out_blob][0]))[::-1]
for i in range(5):
print(idx[i]+1, res[out_blob][0][idx[i]])
cv2.waitKey(3*1000)
```