The common algorithmic model samples are located at 02_preq_examples/, 03_classification/, 04_detection/ and 07_segmentation/ folders in the horizon_model_convert_sample path.
The dataset can be downloaded from the following address.
| Dataset | Address |
|---|---|
| ImageNet | https://www.image-net.org/download.php |
| COCO | https://cocodataset.org/ |
| VOC | http://host.robots.ox.ac.uk/pascal/VOC/ (need to download both versions 2007 and 2012) |
| Cityscapes | https://github.com/mcordts/cityscapesScripts |
| CIFAR-10 | http://www.cs.toronto.edu/~kriz/cifar.html |
To facilitate your subsequent steps, after the dataset has been downloaded, you need to process the evaluation dataset according to the structure suggested by Horizon below.
| Dataset | Description |
| ImageNet Dataset | We recommend that you unzip the downloaded dataset into the following structure. Please contact Horizon if you encounter any problems during data preparation.
|
| COCO Dataset | We recommend that you unzip the downloaded dataset into the following structure. Please contact Horizon if you encounter any problems during data preparation.
|
| VOC Dataset | Attention
|
| Citys capes Dataset | We recommend that you unzip the downloaded dataset into the following structure. Please contact Horizon if you encounter any problems during data preparation.
|
| CIF AR-10 Dataset | We recommend that you unzip the downloaded dataset into the following structure. Please contact Horizon if you encounter any problems during data preparation.
|
When using the model conversion sample package, please prepare the corresponding floating-point model first.
If you need to do this process in the sample folder, you need to execute the 00_init.sh script in the folder first to get the corresponding original model and dataset.
Sources and modifications (if any) of the original models, please refer to below subsections.
model source: https://github.com/shicai/MobileNet-Caffe
md5sum code:
| md5sum | File |
|---|---|
| 3fd6889ec48bda46451d67274144e2a8 | mobilenet.caffemodel |
| 8922f90f629d428fecf866e798ac7c08 | mobilenet_deploy.prototxt |
model source: https://github.com/shicai/MobileNet-Caffe
md5sum code:
| md5sum | File |
|---|---|
| 54aab8425ea068d472e8e4015f22360c | mobilenet_v2.caffemodel |
| 13101ee86ab6d217d5fd6ed46f7a4faa | mobilenet_v2_deploy.prototxt |
model source: https://pytorch.org/vision/main/models/generated/torchvision.models.resnet50.html
md5sum code:
| md5sum | File |
|---|---|
| ebaeb70c972d1a3e6eb06c0e1541eeb4 | resnet50.onnx |
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/GoogleNet
md5sum code:
| md5sum | File |
|---|---|
| f107ae6806ea1016afbc718210b7a617 | googlenet.onnx |
To quickly start running samples and avoid the risks caused by third party tools, we strongly recommend using the off-the-shelf ONNX model in the model_zoo/mapper/ directory in Horizon model release package. If you are interested in reproducing the model conversion process of tflite2onnx, you can still try using the below 3rd-party tool, however, we do not guarantee the quality and success of the conversion.
model source: obtain the TAR package from https://github.com/tensorflow/tpu/tree/master/models/official/efficientnet/lite
md5sum of the converted ONNX models in Horizon model_zoo:
| md5sum | File |
|---|---|
| 001a329bd367fbec22b415c7a33d7bdb | efficientnet_lite0_fp32.onnx |
| 1205e95aea66650c71292bde236d55a9 | efficientnet_lite1_fp32.onnx |
| 474741c15494b79a89fe51d89e0c43c7 | efficientnet_lite2_fp32.onnx |
| 550455b41848d333f8359279c89a6bae | efficientnet_lite3_fp32.onnx |
| bde7fe57eadb4a30ef76f68da622dcd5 | efficientnet_lite4_fp32.onnx |
Download and get .tflite from the TAR package, and then convert it to an ONNX model using the tflite2onnx tool (https://pypi.org/project/tflite2onnx/).
Note that model layouts may vary by tflite2onnx version. If the input layout of the converted ONNX model is NHWC, when building, the configure input_layout_train of the EfficientNet_Lite0/1/2/3/4 should be NHWC.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/VargConvNet
md5sum code:
| md5sum | File |
|---|---|
| e21b8db17916f9046253bbe0bb8de3ef | vargconvnet.onnx |
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/EfficientnasNet
md5sum code:
| md5sum | File |
|---|---|
| fc36c052c6f034c0b64a6197b91b0c62 | efficientnasnet-m.onnx |
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/EfficientnasNet
md5sum code:
| md5sum | File |
|---|---|
| e2744bd748f4265f4488676835a6ca24 | efficientnasnet-s.onnx |
model source: https://pytorch.org/vision/main/models/generated/torchvision.models.resnet18.html
md5sum code:
| md5sum | File |
|---|---|
| 62de4ff68317c65ab4bb6a451e719e6d | resnet18.onnx |
remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.As this conversion tool is a simplified version, you should modify the .prototxt file generated by this tool before the conversion, change the 'Reshape' layer to 'Passthrough' layer, and then add an NCHW2NHWC Permute operation to the output node.
For details about the parameters of the modified Passthrough layer, refer to the yolov2.prototxt sample.
2.md5sum code:
| md5sum | File |
|---|---|
| 7aa7a6764401cebf58e73e72fcbd2a45 | yolov2.caffemodel |
| 72e9a51c1e284e4b66e69f72ca9214c8 | yolov2_transposed.prototxt |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.
URL: https://github.com/ChenYingpeng/caffe-yolov3/ .
The caffemodel file can be downloaded from the Baidu Cloud URL provided in the README.md file in GitHub, in which you should add an NCHW2NHWC Permute operation to the output node.
md5sum code:
| md5sum | File |
|---|---|
| 935af6e1530af5c0017b3674adce95e9 | yolov3_transposed.prototxt |
| 9a0f09c850656913ec27a6da06d9f9cc | yolov3.caffemodel |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.
When cloning the source code, be sure to use [v2.0] tags, otherwise the conversion may fail.
md5sum code:
| md5sum | File |
|---|---|
| 2e296b5e31bf1e1b6b8ea4bf36153ea5 | yolov5l.pt |
| 16150e35f707a2f07e7528b89c032308 | yolov5m.pt |
| 42c681cf466c549ff5ecfe86bcc491a0 | yolov5s.pt |
| 069a6baa2a741dec8a2d44a9083b6d6e | yolov5x.pt |
Remove the reshape from 4D to 5D at the end of each output branch (i.e., not splitting the channel from 255 to 3x85), then convert the layout from NHWC to NCHW before dumping.
The bottom left image displays the visualization of a certain output node before modifying the model, while the bottom right image displays the visualization of the corresponding output node after the modification.
When using the export.py script:
opset_version parameter in the torch.onnx.export as per the version you use.torch.onnx.export from 'image' into 'data' to keep it consistent with that of in the YOLOv5s sample in the model conversion sample package.parser.add_argument from 640x640 to 672x672 as in the YOLOv5x sample in the model conversion sample package.To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.
SSD_MobileNetv1 model: Obtain the Caffe model from URL: https://github.com/chuanqi305/MobileNet-SSD
md5sum code:
| md5sum | File |
|---|---|
| bbcb3b6a0afe1ec89e1288096b5b8c66 | mobilenet_iter_73000.caffemodel |
| 3c230e4415195a50c6248be80c49882d | MobileNetSSD_deploy.prototxt |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/EfficientDet
md5sum code:
| md5sum | File |
|---|---|
| ec4129c4b300cd04f1e8f71e0fe54ca5 | efficientdet_nhwc.onnx |
To achieve optimal on-board performance:
We put the maxpool and sigmoid nodes into the model and specify them to be compiled as BPU nodes for reducing the amount of computation during post-processing.
We modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/Centernet
md5sum code:
| md5sum | File |
|---|---|
| db195ff784792f475e573c5126401d2a | centernet_resnet101_coco_modify.onnx |
remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.model source: https://github.com/HorizonRobotics-Platform/ModelZoo/blob/master/Fcos_Efficientnetb0
md5sum code:
| md5sum | File |
|---|---|
| 9f9a1fe8508e2bd068e70146eb559b4f | fcos_efficientnetb0.onnx |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/YoloV4
md5sum code:
| md5sum | File |
|---|---|
| aaa3c3e5e4c4c1d4830b6501b1720e4d | yolov4_efficientnetb0.onnx |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.
URL: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/Yolov3_VargDarknet . The model file can be downloaded from the Baidu Cloud URL provided in the README.md file in GitHub.
md5sum code:
| md5sum | File |
|---|---|
| fd4e46bc7c9798b51778d3aa09c5053a | yolov3_vargdarknet53.onnx |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/Fcos_Resnet50
md5sum code:
| md5sum | File |
|---|---|
| 0218942777615fac2f54cefdac4fbfa7 | fcos_resnet50.onnx |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/Fcos_Resnext101
md5sum code:
| md5sum | File |
|---|---|
| 4b80efd22448021721ac5a860909c59f | fcos_resnext101.onnx |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Dequantize node from the hbm model.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/MobilenetUnet
md5sum code:
| md5sum | File |
|---|---|
| 21c6c645ebca92befbebc8c39d385c1e | tf_unet_trained.onnx |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Reshape and Cast node from the hbm model.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/DeeplabV3Plus
md5sum code:
| md5sum | File |
|---|---|
| cf3a683f31b4b0ebe090647729f869d9 | deeplabv3plus_efficientnetb0.onnx |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Reshape and Cast node from the hbm model.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/FastSCNN
md5sum code:
| md5sum | File |
|---|---|
| c1ace8f08a9c7b9c91509fa68327d0c8 | fastscnn_efficientnetb0.onnx |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Transpose node from the hbm model.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/DeeplabV3Plus
md5sum code:
| md5sum | File |
|---|---|
| ad002e572cbb49e1e99d893aac69f3e3 | deeplabv3_cityscapes_dila1248_permute.onnx |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Reshape, Cast, and Transpose node from the hbm model.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/DeeplabV3Plus
md5sum code:
| md5sum | File |
|---|---|
| 0a1dfd01e173c68630d9e8dc1a6036fe | deeplabv3plus_efficientnetm1.onnx |
To achieve optimal on-board performance, we modified the remove_node_type parameter in the YAML file used for hbm model compilation and removed the Reshape, Cast, and Transpose node from the hbm model.
model source: https://github.com/HorizonRobotics-Platform/ModelZoo/tree/master/DeeplabV3Plus
md5sum code:
| md5sum | File |
|---|---|
| c11a2673c4b3cf6e5d7bf1a051925d38 | deeplabv3plus_efficientnetm2.onnx |
Taking the GoogleNet model as an example, This section illustrates the steps of floating-point to fixed-point model conversion by using the scripts in 03_classification/04_googlenet/.
First complete the docker installation and configuration and enter the docker container accoridng to Docker Container Deployment .
Execute 00_init.sh in the 03_classification/04_googlenet/ folder to obtain the model and calibration dataset needed for the current sample.
1.Run the script as follows:
2.Output the model inspection result:
Use the hb_compile tool to check whether the model can be supported by Horizon ASIC.
Run the 02_preprocess.sh script in the same directory, as follows:
hb_compile tool will load data from the converted binary data, the format of the pre-processed binary data file is npy, the dtype is unit8.Run the 03_build.sh script in the same directory, as follows:
The above script uses the hb_compile tool to convert the model. The most important thing to focus on is the conversion configuration file, refer to Model Quantized Compilation section.
The output of the above script is as follows:
For now you ONLY need to focus on the googlenet_224x224_nv12.hbm file.
Run the 04_inference.sh script to inference a single image, as follows:
sh 04_inference.sh.05_evaluate.sh.Run the 05_evaluate.sh script to evaluate the accuracy, as follows:
sh 05_evaluate.sh.-p option; meanwhile, pay attention to the memory usage. When the value of the -p option is set to 0 or left unfilled, the fixed-point models in the CPU environment will be processed by 10 processes, while other scenarios using 1 process.There are two possible reasons:
No need to worry much about this situation, the records provided in the documentation is only for reference, and it is ok that your reproduced accuracy is slightly different from those in documents.
In the standard delivery, when adding the example, we have already aligned the fixed-point model accuracy with the hbm on-board accuracy in the ai_benchmark example.
If you find any unaligned accuracy, we recommend you first checking the model input for consistency.
When executing the fixed-point model evaluation script, you use the dataset of image type, while for the hbm model used on board, you use the binary dataset converted by the hb_eval_preprocess tool.
Based on this, if the dataset you used on-board is not generated by using the above methods, we recommend that you first use our data preprocessing tool (i.e., hb_eval_preprocess) to regenerate the dataset needed for on-board running on the same server that you run the fixed-point model accuracy and rerun the on-board accuracy to ensure the model inputs are consistent.
Make sure to use the same environment to generate the dataset by using the hb_eval_preprocess tool and to run the fixed-point model accuracy.