Files
SDK_SG200x_V2/cviruntime/samples/classifier_multi_batch
carbon e25f20f7a3 add cviruntime
commit 3f4938648950a7f3bf9a19c320ca9fae7c52de20
Author: sophgo-forum-service <forum_service@sophgo.com>
Date:   Mon May 13 13:44:23 2024 +0800

    [feat] cviruntime opensource for cv18xx soc.

    - a4b6a3, add cumsum and gatherelements_pt.
2024-05-31 11:51:34 +08:00
..
2024-05-31 11:51:34 +08:00
2024-05-31 11:51:34 +08:00
2024-05-31 11:51:34 +08:00

Sample with Multiple batch fuse cvimodel

Download the mobilev2 model and convert the model under docker (optional)

Model could clone from:https://github.com/shicai/MobileNet-Caffe

For new toolchain guide

The following documents are required:

  • tpu-mlir_xxxx.tar.gz (The release package of tpu-mlir)

Transform cvimodel shell:

tar zxf tpu-mlir_xxxx.tar.gz
source tpu-mlir_xxxx/envsetup.sh

mkdir workspace && cd workspace
cp $TPUC_ROOT/regression/image/cat.jpg .
cp -rf $TPUC_ROOT/regression/dataset/ILSVRC2012 .

model_transform.py \
--model_name mobilenet_v2 \
--model_def ./mobilenet_v2_deploy.prototxt \
--model_data ./mobilenet_v2.caffemodel \
--test_input ./cat.jpg \
--test_result mobilenet_v2_top_output.npz \
--input_shapes [[1,3,224,224]]
--resize_dims 256,256 \
--mean 103.94,116.78,123.68 \
--scale 0.017,0.017,0.017 \
--pixel_format "bgr" \
--tolerance 0.99,0.99 \
--excepts prob \
--mlir mobilenet_v2.mlir

run_calibration.py \
mobilenet_v2.mlir \
--dataset=./ILSVRC2012 \
--input_num=100 \
-o mobilenet_v2_calibration_table

model_deploy.py \
--mlir mobilenet_v2.mlir \
--calibration_table mobilenet_v2_calibration_table \
--chip cv183x \
--quantize INT8 \
--quant_input \
--test_input mobilenet_v2_in_f32.npz \
--test_reference mobilenet_v2_top_output.npz \
--excepts prob \
--tolerance 0.9,0.6 \
--model tmp_model_bs1.cvimodel


model_transform.py \
--model_name mobilenet_v2 \
--model_def ./mobilenet_v2_deploy.prototxt \
--model_data ./mobilenet_v2.caffemodel \
--test_input ./cat.jpg \
--test_result mobilenet_v2_top_output.npz \
--input_shapes [[4,3,224,224]]
--resize_dims 256,256 \
--mean 103.94,116.78,123.68 \
--scale 0.017,0.017,0.017 \
--pixel_format "bgr" \
--tolerance 0.99,0.99 \
--excepts prob \
--mlir mobilenet_v2.mlir

model_deploy.py \
--mlir mobilenet_v2.mlir \
--calibration_table mobilenet_v2_calibration_table \
--chip cv183x \
--quantize INT8 \
--quant_input \
--test_input mobilenet_v2_in_f32.npz \
--test_reference mobilenet_v2_top_output.npz \
--excepts prob \
--tolerance 0.9,0.6 \
--model tmp_model_bs4.cvimodel

model_tool --combine tmp_model_bs1.cvimodel tmp_model_bs4.cvimodel -o mobilenet_v2_bs1_bs4.cvimodel

For old toolchain guide

The following documents are required:

  • cvitek_mlir_ubuntu-18.04.tar.gz

Transform model shell:

tar zxf cvitek_mlir_ubuntu-18.04.tar.gz
source cvitek_mlir/cvitek_envs.sh

mkdir workspace && cd workspace
cp $MLIR_PATH/tpuc/regression/data/cat.jpg .
cp -rf $MLIR_PATH/tpuc/regression/data/images .

model_transform.py \
--model_type caffe \
--model_name mobilenet_v2 \
--model_def mobilenet_v2_deploy.prototxt \
--model_data mobilenet_v2.caffemodel \
--image cat.jpg \
--image_resize_dims 256,256 \
--net_input_dims 224,224 \
--mean 103.94,116.78,123.68 \
--input_scale 0.017 \
--model_channel_order bgr \
--tolerance 0.999,0.999,0.998 \
--excepts prob \
--mlir mobilenet_v2_fp32.mlir

run_calibration.py \
mobilenet_v2_fp32.mlir \
--dataset=./images \
--input_num=100 \
-o mobilenet_v2_calibration_table

model_deploy.py \
--model_name mobilenet_v2 \
--mlir mobilenet_v2_fp32.mlir \
--calibration_table mobilenet_v2_calibration_table_1000 \
--chip cv183x \
--image cat.jpg \
--merge_weight \
--tolerance 0.94,0.94,0.66 \
--excepts prob \
--correctness 0.99,0.99,0.99 \
--cvimodel tmp_model_bs1.cvimodel

model_transform.py \
--model_type caffe \
--model_name mobilenet_v2 \
--model_def mobilenet_v2_deploy.prototxt \
--model_data mobilenet_v2.caffemodel \
--image cat.jpg \
--image_resize_dims 256,256 \
--net_input_dims 224,224 \
--mean 103.94,116.78,123.68 \
--input_scale 0.017 \
--model_channel_order bgr \
--batch_size 4 \
--tolerance 0.999,0.999,0.998 \
--excepts prob \
--mlir mobilenet_v2_fp32.mlir

model_deploy.py \
--model_name mobilenet_v2 \
--mlir mobilenet_v2_fp32.mlir \
--calibration_table mobilenet_v2_calibration_table_1000 \
--chip cv183x \
--image cat.jpg \
--merge_weight \
--tolerance 0.94,0.94,0.66 \
--excepts prob \
--correctness 0.99,0.99,0.99 \
--cvimodel tmp_model_bs4.cvimodel

cvimodel_tool \
-a merge \
-i tmp_model_bs1.cvimodel tmp_model_bs4.cvimodel \
-o mobilenet_v2_bs1_bs4.cvimodel

Copy generated mobilenet_v2_bs1_bs4.cvimodel to Development board

How To Compile Sample In Docker

View the Top level directory README.md or View the cvitek_tpu_quick_start_guide.md

Run Samples In EVB Borad

cd install_samples
./bin/cvi_sample_classifier_multi_batch \
./mobilenet_v2_bs1_bs4.cvimodel \
./data/cat.jpg \
./data/synset_words.txt