原始论文出处: https://arxiv.org/abs/1611.09326
Github repo: https://github.com/dlod-openvino/100-tiramisu-keras
环境搭建步骤:
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
训练模型:
Step 1:克隆repo:
git clone https://github.com/dlod-openvino/100-tiramisu-keras.git
Step 2:下载模型权重文件到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/下载训练数据集
Step 5: 脚本train.py,启动训练
python train.py
基于OpenVINO优化并部署模型:
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 模型转换为 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 运行时环境
c:\Program Files (x86)\Intel\openvino_2021.2.185>bin\setupvars.bat
STEP5: 将 onnx 模型转化为 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 脚本,执行推理计算
D:\100-tiramisu-keras>python ov_infer_demo.py -d CPU

网友评论