# OpenVINO 環境建制參考資料
## 本機開發環境
1. [如何利用Docker快速建置OpenVINO™ Toolkit開發環境](https://makerpro.cc/2021/01/use-docker-to-develop-the-environment-of-openvino/)
2. [Docker Hub OpenVINO](https://hub.docker.com/u/openvino)
## Intel DevCloud
1. [OpenVINO雲端也能GO!四個步驟輕鬆在DevCloud實作AI推論](https://makerpro.cc/2021/09/four-steps-to-easily-realize-ai-inference-on-intel-devcloud)
### 建議架設完成 測試是否可以在環境中轉換自己訓練的模型
1. 使用tensorflow 訓練自己的模型
[Object Detection APi物件辨識分類器實作-採用TensorFlow (CPU) ](https://medium.com/@9821343/object-detection-api%E7%89%A9%E4%BB%B6%E8%AD%98%E5%88%A5%E5%88%86%E9%A1%9E%E5%99%A8%E5%AF%A6%E4%BD%9C-%E6%8E%A1%E7%94%A8tensorflow-cpu-%E5%9C%A8windows-10%E4%B8%8A-83d73065f27f)
2. 將訓練完成的tf模型 轉換並部署到openvino的環境運行
[Intel OpenVINO 模型轉換 — TensorFlow, Darknet YOLO, ONNX](https://medium.com/ching-i/intel-openvino-%E6%A8%A1%E5%9E%8B%E8%BD%89%E6%8F%9B-tensorflow-darknet-yolo-onnx-cfc9f2260e7f)
### Ubuntu 20.04 Install OpenVINO
1. 前置作業 `sudo apt install make gcc`
2. 安裝 OpenVINO 套件: https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_apt.html
3. 安裝並檢測 Intel 硬體: https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_linux_ivad_vpu.html
4. 
5. 影像辨識 DEMO 環境: https://docs.openvino.ai/latest/openvino_docs_get_started_get_started_scripts.html
6. 
### OpenVINO x OpenCV Python3 環境建制
> 備註:如果欲採用 conda python 虛擬環境,可跳過此章節,請看[下一章節](#Install-anaconda-on-Ubuntu2004)
1. 安裝 python3 相依套件 `sudo pip3 install opencv-python openvino scipy`
2. 測試:`python3 /opt/intel/openvino_2021/inference_engine/demos/human_pose_estimation_demo/python/human_pose_estimation_demo.py -h`
3. 測試結果:
### Install anaconda on Ubuntu20.04
* [Install openvino for python (anacondaa)](https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_conda.html)
* 下載 linux 安裝檔: `wget https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.sh`
* 執行安裝 anaconda 檔: **不要用 ROOT/SUDO 權限執行**
```shell=
$ chmod +x Anaconda3-2021.11-Linux-x86_64.sh
$ ./Anaconda3-2021.11-Linux-x86_64.sh
.......
Do you accept the license terms? [yes|no]
[no] >>> yes
Anaconda3 will now be installed into this location:
/<USER_NAME>/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/<USER_NAME>/anaconda3] >>>
PREFIX=/<USER_NAME>/anaconda3
Unpacking payload ...
.....
Preparing transaction: done
Executing transaction: /
Installed package of scikit-learn can be accelerated using scikit-learn-intelex.
More details are available here: https://intel.github.io/scikit-learn-intelex
For example:
$ conda install scikit-learn-intelex
$ python -m sklearnex my_application.py
done
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes
./Anaconda3-2021.11-Linux-x86_64.sh: 489: [[: not found
no change /<USER_NAME>/anaconda3/condabin/conda
no change /<USER_NAME>/anaconda3/bin/conda
no change /<USER_NAME>/anaconda3/bin/conda-env
no change /<USER_NAME>/anaconda3/bin/activate
no change /<USER_NAME>/anaconda3/bin/deactivate
no change /<USER_NAME>/anaconda3/etc/profile.d/conda.sh
no change /<USER_NAME>/anaconda3/etc/fish/conf.d/conda.fish
no change /<USER_NAME>/anaconda3/shell/condabin/Conda.psm1
no change /<USER_NAME>/anaconda3/shell/condabin/conda-hook.ps1
no change /<USER_NAME>/anaconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change /<USER_NAME>/anaconda3/etc/profile.d/conda.csh
modified /<USER_NAME>/.bashrc
==> For changes to take effect, close and re-open your current shell. <==
If you'd prefer that conda's base environment not be activated on startup,
set the auto_activate_base parameter to false:
conda config --set auto_activate_base false
Thank you for installing Anaconda3!
```
* 測試 conda 是否有安裝成功:
```shell=
$ ~/anaconda3/bin/conda -h
usage: conda [-h] [-V] command ...
conda is a tool for managing and deploying applications, environments and packages.
Options:
positional arguments:
command
clean Remove unused packages and caches.
compare Compare packages between conda environments.
config Modify configuration values in .condarc. This is modeled after the
git config command. Writes to the user .condarc file
(/home/sss2500/.condarc) by default.
create Create a new conda environment from a list of specified packages.
help Displays a list of available conda commands and their help strings.
info Display information about current conda install.
init Initialize conda for shell interaction. [Experimental]
install Installs a list of packages into a specified conda environment.
list List linked packages in a conda environment.
package Low-level conda package utility. (EXPERIMENTAL)
remove Remove a list of packages from a specified conda environment.
uninstall Alias for conda remove.
run Run an executable in a conda environment. [Experimental]
search Search for packages and display associated information. The input
is a MatchSpec, a query language for conda packages. See examples
below.
update Updates conda packages to the latest compatible version.
upgrade Alias for conda update.
optional arguments:
-h, --help Show this help message and exit.
-V, --version Show the conda version number and exit.
conda commands available from other packages:
build
.......
```
* 終端機關閉重開,或是重新登入,以確定載入新的 .bashrc 檔案
* Set up the Anaconda* environment:
```
(base) $ conda create --name py38 python=3.8 # 我們的 python 版本是 3.8 這邊帶入 3.8
(base) $ conda activate py38 #切換環境
(py38) $ # 確認已切換環境
(py38) $ conda install numpy
(py38) $ conda install openvino-ie4py-ubuntu20 -c intel
(py38) $ pip3 install opencv-python openvino scipy # pip 安裝相依套件 openvino opencv scipy
(py38) $ python -c "from openvino.inference_engine import IECore" # 測試相依套件是否正常
(py38) $ # 正常會顯示空值,如果有相依套件問題,這邊會顯示錯誤訊息
```
* 
* 在 conda 虛擬環境中執行測試:
```
(py38) $ python /opt/intel/openvino_2021/inference_engine/demos/human_pose_estimation_demo/python/human_pose_estimation_demo.py -h
```
* 
* 修改 Intel 官方的範例程式: `$ sudo vim /opt/intel/openvino_2021/deployment_tools/demo/demo_squeezenet_download_convert_run.sh
`
* 第 150 行處移除 sudo 字眼(因為 conda 環境中 pip 套件不使用 sudo 安裝至系統中)
* 
* intel 的 demo script 都用 sudo 安裝 pip 套件,若要執行其他測試 script 需要移除 sudo 字眼就可以正常在 conda 虛擬環境中執行了
* 執行 intel 的測試案例:
```shell=
(py38) $ cd /opt/intel/openvino_2021/deployment_tools/demo
(py38) /opt/intel/openvino_2021/deployment_tools/demo $ ./demo_squeezenet_download_convert_run.sh
```
* 