Online AI Model Conversion Guide
Introduction to Online AI Model Conversion
This guide shows the process of converting AI models using the online conversion tool. The online conversion tool allows you to upload your model files and convert them into a format compatible with the Ameba IC.
Note: Please log in to access the online conversion tool.
Refer to the following table for online conversion supported models currently.
Models |
Basic functions |
Required files |
|---|---|---|
yolov3-tiny, darknet |
Object Detection |
“.cfg”, “.weights” |
yolov4-tiny, darknet |
Object Detection |
“.cfg”, “.weights” |
yolov7-tiny, darknet |
Object Detection |
“.cfg”, “.weights” |
yolov7-tiny, pytorch |
Object Detection |
“.pt” |
scrfd/mobilefacenet |
Face Detection & Recognition |
“.pt” or “.onnx” |
yamnet |
Sound Classification |
“.h5” |
CNN Gray/RGB |
Image Classification |
“.h5” or “.onnx” |
The quantize images are optional for uploading that up to 10.
For CNN Gray/RGB, please refer to the following instructions to get the correct converted models.
When training model: supported tensorflow version up to 2.14.1
When saving model: set flag as “include_optimizer=False”
After AI Model Conversion, there will be download link send out by email.
For more information on model deployment, please refer to the Customized AI model Deployment Guide .
For MobileFaceNet .pt to .onnx model conversion guide, please refer to MobileFaceNet ONNX Conversion section for more details.
For SCRFD .pt to .onnx model conversion guide, please refer to SCRFD Conversion To ONNX section for more details.
MobileFaceNet ONNX Conversion
MobileFaceNet is an efficient Convolutional Neural Network (CNN) model and it uses more than 1 million parameters.
MobileFaceNet is used for feature extractions. Since MobileFaceNet is one of the types of light weights models, we can apply this face recognition system on mobile and embedded devices.
We can download the source code and pretrained model from GitHub:
git clone https://github.com/foamliu/MobileFaceNet.git.
cd MobileFaceNet
mkdir weights
cd weights
wget https://github.com/foamliu/MobileFaceNet/releases/download/v1.0/mobilefacenet.pt
For better performance and compatibility, makers can convert .pt to .onnx by executing:
python3 convert2onnx.py
Code Reference
convert2onnx.py
from mobilefacenet import MobileFaceNet
import torch
import time
if __name__ == '__main__':
filename = 'weights/mobilefacenet.pt'
print('loading {}...'.format(filename))
start = time.time()
model = MobileFaceNet()
model.load_state_dict(torch.load(filename, map_location=torch.device('cpu')))
print('elapsed {} sec'.format(time.time() - start))
print(model)
output_onnx = 'weights/MobileFaceNet.onnx'
print("==> Exporting model to ONNX format at '{}'".format(output_onnx))
input_names = ["input0"]
output_names = ["output0"]
inputs = torch.randn(1, 3, 112, 112)
torch_out = torch.onnx._export(model, inputs, output_onnx, export_params=True, verbose=False,
input_names=input_names, output_names=output_names, opset_version=10)
The converted onnx will be located at weights/MobileFaceNet.onnx.
SCRFD Conversion To ONNX
SCRFD is an efficient high accuracy face detection approach which is initialy described in Arxiv.
It provides an easy-to-use pipeline to train high efficiency face detectors with NAS supporting.
You can visit InsignFace to get more information.
For edge computing application, makers are recommended to use SCRFD_500M_KPS.
Set Environment for SCRFD
The default format of SCRFD is pytorch, so it has to be converted to ONNX format:
cd ~/insightface/detection/scrfd
python tools/scrfd2onnx.py configs/scrfd/scrfd_500m_bnkps.py scrfd_500mkps.pt --shape 640 640
You can fine tools/scrfd2onnx.py in InsignFace.
If Makers encounter Python package dependency issues, they can try creating isolated Python environments with virtualenv and referring to our requirements_scrfd.txt to install Python packages. Kindly download it from requirements_scrfd
pip install -r requirements_scrfd.txt
In order to show you how to translate and export SCRFD quickly, we can download the pretrained weights from Internet: scrfd.lite.ai.toolkit
Please download scrfd_500m_bnkps_shape640x640.onnx or scrfd_500m_bnkps_shape320x320.onnx for edge computing application.