原始論文出處: https://arxiv.org/abs/1611.09326
Github repo: https://github.com/dlod-openvino/100-tiramisu-keras
環(huán)境搭建步驟:
Step 1: Create a environment in Anaconda with python=3.8:
conda create -n tf2_2 python=3.8
Step 2: Install tensorflow 2.2:
pip install --ignore-installed --upgrade tensorflow==2.2.0
Step 3: Install cudatoolkit=10.1 cudnn=7.6.5
conda install cudatoolkit=10.1 cudnn=7.6.5
Step 4: Install Keras==2.4.3 pillow
pip install keras==2.4.3 pillow
訓(xùn)練模型:
Step 1:克隆repo:
git clone https://github.com/dlod-openvino/100-tiramisu-keras.git
Step 2:下載模型權(quán)重文件到models/文件夾
百度云盤 提取碼:9xy0
Step 3: 運行腳本 python run_tiramisu_camvid.py
python run_tiramisu_camvid.py
Step 4: 從http://mi.eng.cam.ac.uk/research/projects/VideoRec/CamVid/下載訓(xùn)練數(shù)據(jù)集
Step 5: 腳本train.py因块,啟動訓(xùn)練
python train.py
基于OpenVINO優(yōu)化并部署模型:
STEP1: 安裝 keras2onnx 工具包: https://pypi.org/project/keras2onnx/ :
pip install -U git+https://github.com/microsoft/onnxconverter-common
pip install -U git+https://github.com/onnx/keras-onnx
STEP2: 將 Keras h5 模型轉(zhuǎn)換為 ONNX 模型, 運行腳本:convert_to_onnx.py :
from keras.models import Model
from keras.layers import *
from tiramisu.model import create_tiramisu
import keras2onnx
# Set the weight file name
keras_model_weights = "models/my_tiramisu.h5"
onnx_model_weights = keras_model_weights.split('.')[0]+'.onnx'
# Load model and weights
input_shape = (224, 224, 3)
number_classes = 32 # CamVid data consist of 32 classes
# Prepare the model information
img_input = Input(shape=input_shape, batch_size=1)
x = create_tiramisu(number_classes, img_input)
model = Model(img_input, x)
# Load the keras model weights
model.load_weights(keras_model_weights)
onnx_model = keras2onnx.convert_keras(model, model.name)
# Save the onnx model weights
keras2onnx.save_model(onnx_model, onnx_model_weights)
運行Python腳本 convert_to_onnx.py
python convert_to_onnx.py
STEP3: 安裝 OpenVINO 2021.2: openvino_2021.2.185
STEP4: 初始化 OpenVINO 運行時環(huán)境
c:\Program Files (x86)\Intel\openvino_2021.2.185>bin\setupvars.bat
STEP5: 將 onnx 模型轉(zhuǎn)化為 IR 模型
c:\Program Files (x86)\Intel\openvino_2021.2.185\deployment_tools\model_optimizer>python mo_onnx.py --input_model d:\100-tiramisu-keras\models\my_tiramisu.onnx --output_dir d:\100-tiramisu-keras\models
STEP6: 運行 ov_infer_demo.py 腳本,執(zhí)行推理計算
D:\100-tiramisu-keras>python ov_infer_demo.py -d CPU
運行結(jié)果