# AI 深度學習與視覺運算 –以OpenVINO 和 Phython 實例介紹
## 安裝 OpenVINO Development Tools (PypI package)
[Installing OpenVINO™ Development Tools](https://docs.openvino.ai/latest/openvino_docs_install_guides_install_dev_tools.html#install-dev-tools)
Step 1. 設定 Python 虛擬環境
```
python -m venv openvino_env
```
Step 2. 啟動虛擬環境
```
Scripts\activate
```
Step 3. Set Up and Update PIP to the Highest Version
```
python -m pip install --upgrade pip
```
Step 4. Install the Package
```
pip install openvino-dev[tensorflow2,onnx,pytorch]
```
Step 5. Test the Installation
```
mo -h
```
---
## 安裝 Jupyter Notebook
```
pip install jupyter
```
---
## 執行 Jupyter Notebook
下載[00 OpenVINO Quick Get Started.ipynb](https://drive.google.com/drive/folders/1lLvl45Y2E8z8yiR16M8efsgr3giC9vzb?usp=sharing)到C:\Users\\<font color="#f00">xxx</font>\openvino_env 路徑下
在虛擬環境下執行
```
jupyter notebook
```
[car](https://drive.google.com/file/d/1wFZbFWmzh6iDgr1G8H-JeD17Quwn3LTs/view?usp=share_link)
---
## 如何進入OpenVINO 開發虛擬環境
搜尋"命令列" or "command prompt" 並執行
啟動虛擬環境
```
Scripts\activate
```
---
## Pre-trained Models
[Intel’s Pre-Trained Models
](https://docs.openvino.ai/latest/omz_models_group_intel.html
)
[Public Pre-Trained Models
](https://docs.openvino.ai/latest/omz_models_group_intel.html
)
---
## Demo Applications
[Demo Applications
](https://docs.openvino.ai/latest/omz_demos.html
)
---
## 下載Open Model Zoo
由以下網址[Open Model Zoo](https://github.com/openvinotoolkit/open_model_zoo/archive/refs/heads/releases/2022/2.zip
), 直接下載 2022.2 release 壓縮檔
把下載的open_model_zoo-releases-2022-2解壓縮到 , 比如解壓縮到c:\users\\<font color="#f00">xxx</font>\open_model_zoo.
執行
```
Scripts\activate
```
執行
```
pip install -r \open_model_zoo\demos\requirements.txt
```
測試 Python Demo是否可以執行
切換目錄到 cd \open_model_zoo\demos\object_detection_demo\python
執行
```
set PYTHONPATH=%PYTHONPATH%;c:\Users\colli\open_model_zoo\demos\common\python\
```
執行
```
python object_detection_demo.py -h
```
---
## 執行影像分類範例 (classification demo)
準備工作
設定python API 路徑
```
set PYTHONPATH=%PYTHONPATH%;c:\Users\colli\open_model_zoo\demos\common\python\
```
切換目錄到
```
cd C:\Users\colli\open_model_zoo\demos\classification_demo\python
```
下載與轉換深度學習模型到 IR models
```
omz_downloader --name googlenet-v1
omz_converter --name googlenet-v1
```
執行範例程式
```
python classification_demo.py -m public\googlenet-v1\FP16\googlenet-v1.xml -i dog.bmp -d GPU
```
加入label
```
python classification_demo.py -m public\googlenet-v1\FP16\googlenet-v1.xml -i dog.bmp -d GPU --labels c:\Users\colli\open_model_zoo\data\dataset_classes/imagenet_2012.txt
```
[蔬菜水果分類範例影片
](https://storage.openvinotoolkit.org/test_data/videos/fruit-and-vegetable-detection.mp4
)
[Classification python demo
](https://docs.openvino.ai/latest/omz_demos_classification_demo_python.html
)
[dog](https://drive.google.com/file/d/1U9mQHvxhYRZ6kZBpxLxjmwtWLNX3CRF2/view?usp=share_link)
---
## Python classification_demo.py -h
```
Python classification_demo.py -h
```
---
## 執行Object Detection Demo (SSD)
切換目錄到
```
cd C:\Users\colli\open_model_zoo\demos\object_detection_demo\python
```
下載與轉換深度學習模型到 IR models SSD300
```
omz_downloader --name ssd300
omz_converter --name ssd300
```
執行範例程式 (using USB webcam as input)
```
python object_detection_demo.py -m public\ssd300\FP16\ssd300.xml -i 0 -at ssd --labels C:\Users\colli\open_model_zoo\data\dataset_classes\voc_20cl_bkgr.txt
```
```
python object_detection_demo.py -m public\ssd300\FP16\ssd300.xml -i car-detection.mp4 -at ssd --labels C:\Users\colli\open_model_zoo\data\dataset_classes\voc_20cl_bkgr.txt
```
[汽車偵測範例影片
](https://storage.openvinotoolkit.org/test_data/videos/car-detection.mp4
)
[Object Detection C++ Demo
](https://docs.openvino.ai/latest/omz_demos_object_detection_demo_python.html
)
[ssd300
](https://docs.openvino.ai/latest/omz_models_model_ssd300.html#doxid-omz-models-model-ssd300)
---
## How to Run Text Spotting Python* Demo
切換目錄到
```
cd C:\Users\colli\open_model_zoo\demos\text_spotting_demo\python
```
下載與轉換深度學習模型到 IR models
```
omz_downloader --name text-spotting-0005-detector
omz_downloader --name text-spotting-0005-recognizer-encoder
omz_downloader --name text-spotting-0005-recognizer-decoder
```
執行範例程式
```
python text_spotting_demo.py -m_m intel\text-spotting-0005\text-spotting-0005-detector\FP16\text-spotting-0005-detector.xml -m_te intel\text-spotting-0005\text-spotting-0005-recognizer-encoder\FP16\text-spotting-0005-recognizer-encoder.xml -m_td intel\text-spotting-0005\text-spotting-0005-recognizer-decoder\FP16\text-spotting-0005-recognizer-decoder.xml -i Einstein.png
```
[Text Spotting Python Demo
](https://docs.openvino.ai/latest/omz_demos_text_spotting_demo_python.html
)
[text-spotting-0005
](https://docs.openvino.ai/latest/omz_models_model_text_spotting_0005.html)
[Einstein](https://drive.google.com/file/d/1N8jUoqNpcQ8yVUtkYHhBSff-d_hB0OXz/view?usp=share_link)
---
## How to Run Human Pose Estimation Python* Demo
切換目錄到
```
cd C:\Users\colli\open_model_zoo\demos\human_pose_estimation_demo\python
```
下載Intel深度學習模型
```
omz_downloader --name human-pose-estimation-0005
```
執行範例程式 (using USB webcam as input)
```
python human_pose_estimation_demo.py -d CPU -i 0 -m intel\human-pose-estimation-0005\FP16\human-pose-estimation-0005.xml -at ae
```
執行範例程式 using Video file
```
python human_pose_estimation_demo.py -d CPU -i face-demographics-walking.mp4 -m intel\human-pose-estimation-0005\FP16\human-pose-estimation-0005.xml -at ae
```
[Human Pose Estimation Python* Demo
](https://docs.openvino.ai/latest/omz_demos_human_pose_estimation_demo_python.html
)
[human-pose-estimation-0005
](https://docs.openvino.ai/latest/omz_models_model_human_pose_estimation_0005.html)
[face-demographics-walking 影片檔](https://storage.openvinotoolkit.org/data/test_data/videos/face-demographics-walking.mp4)
---
## 安裝OpenVINO Notebooks
下載 OpenVINO Notebooks 原始碼,https://github.com/openvinotoolkit/openvino_notebooks/archive/refs/heads/main.zip
Install C++ Redistributable (For Python 3.8)- Download [Microsoft Visual C++ Redistributable](https://aka.ms/vs/16/release/vc_redist.x64.exe).
把下載的openvino_notebooks-main.zip解壓縮到 , 比如解壓縮到c:\users\colli\openvino_env\
到目錄c:\users\colli\openvino_env下執行
```
Scripts\activate
```
執行
```
python -m pip install --upgrade pip wheel setuptools
```
執行
```
pip install -r requirements.txt
```
---
## OpenVINO Notebooks
[OpenVINO Notebooks](https://github.com/openvinotoolkit/openvino_notebooks
)
---
## Smart Classroom C++ Demo
Anaconda prompt 下執行
```
conda activate ov_2022_dev
```
```
cd C:\Program Files (x86)\Intel\openvino_2022
setupvars.bat
```
```
cd C:\Users\colli\Documents\Intel\OpenVINO\omz_demos_build\intel64\Release
```
```
smart_classroom_demo -i 1 -m_act intel\person-detection-action-recognition-0006\FP16\person-detection-action-recognition-0006.xml -student_ac "sitting, writing, raising hand, standing, turned around, lie on the desk" -m_fd intel\face-detection-adas-0001\FP16\face-detection-adas-0001.xml -m_reid intel\face-reidentification-retail-0095\FP16\face-reidentification-retail-0095.xml -m_lm intel\landmarks-regression-retail-0009\FP16\landmarks-regression-retail-0009.xml -t_reid 0.8 -fg C:\Users\colli\open_model_zoo\faces_gallery.json
```