# m1000_npu_model_zoo **Repository Path**: MooreThreads-AI-SOC/m1000_npu_model_zoo ## Basic Information - **Project Name**: m1000_npu_model_zoo - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 3 - **Created**: 2025-09-26 - **Last Updated**: 2026-03-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # M1000 NPU Model Zoo 该项目整理了能够在 M1000 NPU 上部署的AI模型,并提供模型转换、部署运行的代码。M1000 NPU 的完整信息,请参考 [MTNN](https://gitee.com/MooreThreads-AI-SOC/m1000_mtnn) 。开发者可参考本项目,快速使用 M1000 NPU,部署自己的AI模型。 ## 一、项目结构 ``` npu_model_zoo/ ├── Image_Classification 图像分类相关网络 ├──001mobilenet_v1 ├──002mobilenet_v3 └──... ├── Object_Detection 目标检测相关网络 ├── Image_Segmentation 图像分割相关网络 ├── Other 其他类型网络 ├── data 常用数据 ├── utils 常用工具 ├── doc 相关文档 ├── test_all.py 测试所有模型mtnn转换的脚本 └── README.md 项目说明 ``` 在任一模型的[文件夹](./Image_Classification/001mobilenet_v1/README.md)下,介绍了该模型的NPU使用方法。 ## 二、如何使用 ### 1、环境安装 本项目依赖 M1000 NPU 相关 SDK,已在板卡中预先安装,需要 SDK 版本 >= 1.4.0 。 若需要更新至最新版本,可参考 [MTNN](https://gitee.com/MooreThreads-AI-SOC/m1000_mtnn) 项目。 创建python的虚拟环境 ```sh conda create -n npu_model_zoo python=3.10 #创建python3.10的虚拟环境 conda activate npu_model_zoo #激活虚拟环境 pip3 install -r requirements.txt #安装第三方依赖 pip3 install ./libmtnn_api_4py-1.4-py3-none-any.whl #安装mtnn_api 由 npu_sdk_v1.4.0.tar.gz 提供 ``` > ⚠️ [whisper-tiny](./Other/006whisper-tiny/README.md)、[wespeaker](./Other/004wespeaker/README.md) 需单独配置环境,在各自的 README.md 中说明 ### 2、模型转换与部署 以mobilenetv1为例,介绍如何快速使用 #### step1:导出model.onnx和input.npy ```shell cd Image_Classification/001mobilenet_v1 python3 ./export.py ``` #### step2:模型转换设置 项目已提供可直接使用的mtc配置文件`mtc_config.yaml`,如需更改,常见关注如下。完整的配置选项,请参考 mtnn_guide 文档。 - `input_file_list` : ./input.npy(⚠️使用相对mtc_config.yaml的路径) - `ModelPath` : ./model.onnx (⚠️使用相对mtc_config.yaml的路径) - `quant_type` : 量化类型(与`quantizer`联合使用) - `quantizer` : 量化方法 #### step3:利用mtc工具进行模型转换 ```shell mtc --config ./mtc_config.yaml ``` 运行后在`/opt/m1000-mtc-toolkit/bin/baselib/data/net_data/onnx/`路径下,生成名为 mtc_config.yaml 中 Name 的文件夹,在该文件夹的`./mtc/dump_npu_files/*_export_data/`中获得转换后的 *.mtnn 模型 #### step4:验证mtnn模型的正确性和部署 除了cos值(>0.99),项目还提供了可运行 mtnn 和 onnx 模型预测的脚本sample.py ```shell python3 ./sample.py --model_path ./model.onnx # onnx模型预测 CPU执行 python3 ./sample.py --model_path ./mobilenetv1.mtnn # mtnn模型预测 NPU执行 ``` 通过比较 mtnn模型和onnx模型的预测结果,进一步验证NPU模型的正确性 进一步进行数据集验证和嵌入式部署 ### 3、进阶处理 项目总结了[MTC工具的常用设置](./doc/mtc_use.md),包含uint8量化、int16量化、混合量化、static量化、fp16量化等。 为使得NPU模型的精度更高,可在量化阶段[配置量化数据集](./data/配置量化数据集.md)。参考 mtnn_guide文档 第十章 配置数据集。 为追求更强的性能,mtnn提供图像前处理接口,可将前处理部分置于NPU执行。参考 mtnn_guide文档 第九章 前处理功能。 ## 三、模型支持 ### 图像分类 Image Classification | | Name|Quant Type|Input Shape|Model Link| | --- | --- | --- | :---: | :---: | |001|[mobilenet_v1](./Image_Classification/001mobilenet_v1/README.md)|INT16|[1,3,224,224]| [🔗](https://huggingface.co/google/mobilenet_v1_1.0_224) | |002|[mobilenet_v3](./Image_Classification/002mobilenet_v3/README.md)|INT16|[1,3,224,224]| [🔗](https://huggingface.co/timm/mobilenetv3_small_100.lamb_in1k) | |003|[vit](./Image_Classification/003vit/README.md)|INT16|[1,3,224,224]| [🔗](https://huggingface.co/google/vit-base-patch16-224) | |004|[nsfw](./Image_Classification/004nsfw/README.md)|UINT8|[1,3,224,224]| [🔗](https://huggingface.co/Falconsai/nsfw_image_detection) | |005|[gender-cls](./Image_Classification/005gender-cls/README.md)|INT16|[1,3,224,224]| [🔗](https://huggingface.co/rizvandwiki/gender-classification) | |006|[swin_vit](./Image_Classification/006swin_vit/README.md)|INT16|[1,3,224,224]| [🔗](https://huggingface.co/timm/swin_s3_tiny_224.ms_in1k) | |007|[efficientnet](./Image_Classification/007efficientnet/README.md)|UINT8|[1,3,260,260]| [🔗](https://huggingface.co/google/efficientnet-b2) | |008|[deit](./Image_Classification/008deit/README.md)|INT16|[1,3,224,224]| [🔗](https://huggingface.co/facebook/deit-base-patch16-224) | |009|[dino_vit](./Image_Classification/009dino_vit/README.md)|INT16|[1,3,224,224]| [🔗](https://huggingface.co/facebook/dinov2-base-imagenet1k-1-layer) | |010|[lenet](./Image_Classification/010lenet/README.md)|UINT8|[1,1,28,28]| [🔗](https://huggingface.co/EclipseAidge/LeNet) | |011|[Alexnet](./Image_Classification/011Alexnet/README.md)|UINT8|[1,3,224,224]| [🔗](https://huggingface.co/Kalray/alexnet) | |012|[VGG](./Image_Classification/012VGG/README.md)|UINT8|[1,3,224,224]| [🔗](https://huggingface.co/timm/vgg16.tv_in1k) | ### 目标检测 Object_Detection | | Name|Quant Type|Input Shape|Model Link| | --- | --- | --- | :---: | :---: | |001|[yolov8m](./Object_Detection/001yolov8m/README.md)|static onnx|[1,3,640,640]|[🔗](https://github.com/ultralytics/ultralytics) | |002|[yolov8s](./Object_Detection/002yolov8s/README.md)|static onnx|[1,3,640,640]|[🔗](https://github.com/ultralytics/ultralytics) | |003|[yolov11m](./Object_Detection/003yolov11m/README.md)|static onnx|[1,3,640,640]|[🔗](https://github.com/ultralytics/ultralytics) | |004|[yolov8m-pose](./Object_Detection/004yolov8m-pose/README.md)|static onnx|[1,3,640,640]|[🔗](https://github.com/ultralytics/ultralytics) | |005|[yolov8s-pose](./Object_Detection/005yolov8s-pose/README.md)|static onnx|[1,3,640,640]|[🔗](https://github.com/ultralytics/ultralytics) | |006|[yolov11m-pose](./Object_Detection/006yolov11m-pose/README.md)|static onnx|[1,3,640,640]|[🔗](https://github.com/ultralytics/ultralytics) | |007|[retinaface(Resnet50)](./Object_Detection/007retinaface_Resnet50/README.md)|INT16|[1,3,640,640]| [🔗](https://github.com/biubug6/Pytorch_Retinaface) | |008|[adaface(R100-WebFace12M)](./Object_Detection/008adaface/README.md)|INT16|[1,3,112,112]| [🔗](https://huggingface.co/minchul/cvlface_adaface_ir101_webface12m) | |009|[yolov5s](./Object_Detection/009yolov5s/README.md)|static onnx|[1,3,640,640]|[🔗](https://github.com/ultralytics/ultralytics) | |010|[efficientdet-d0](./Object_Detection/010efficientDet-D0/README.md)|INT16|[1,3,512,512]| [🔗](https://huggingface.co/Kalray/efficientdet-d0) | |011|[faster-rcnn](./Object_Detection/011faster-rcnn/README.md)|UINT8|[1,3,512,512]| [🔗](https://huggingface.co/Kalray/faster-rcnn-rn50) | |012|[ssd](./Object_Detection/012ssd/README.md)|UINT8|[1,3,300,300]| [🔗](https://huggingface.co/Kalray/ssd-mobilenet-v2) | |013|[detr](./Object_Detection/013detr/README.md)|UINT8|[1,3,800,1066]| [🔗](https://huggingface.co/facebook/detr-resnet-50) | |014|[yolov26m](./Object_Detection/014yolov26m/README.md)|INT8 混合量化|[1,3,640,640]| [🔗](https://github.com/ultralytics/ultralytics) | |015|[yolov5l-classic](./Object_Detection/015yolov5l-classic/README.md)|static onnx|[1,3,640,640]| [🔗](https://github.com/ultralytics/yolov5) | ### 图像分割 Image_Segmentation | | Name|Quant Type|Input Shape|Model Link| | --- | --- | --- | :---: | :---: | |001|[deeplab_v3](./Image_Segmentation/001deeplab_v3/README.md)|INT16|[1,3,513,513]| [🔗](https://huggingface.co/google/deeplabv3_mobilenet_v2_1.0_513) | |002|[Unet](./Image_Segmentation/002Unet/README.md)|INT16|[1,3,640,1280]| [🔗](https://huggingface.co/qualcomm/Unet-Segmentation/tree/main) | |003|[yolov8s-seg](./Image_Segmentation/003yolov8s-seg/README.md)|UINT8 混合量化|[1,3,640,640]|[🔗](https://github.com/ultralytics/ultralytics) | |004|[yolov8m-seg](./Image_Segmentation/004yolov8m-seg/README.md)|UINT8 混合量化|[1,3,640,640]|[🔗](https://github.com/ultralytics/ultralytics) | |005|[yolov11m-seg](./Image_Segmentation/005yolov11m-seg/README.md)|UINT8 混合量化|[1,3,640,640]|[🔗](https://github.com/ultralytics/ultralytics) | |006|[yolov5s-seg](./Image_Segmentation/006yolov5s-seg/README.md)|UINT8 混合量化|[1,3,640,640]| [🔗](https://github.com/ultralytics/yolov5) | |007|[FastSAM](./Image_Segmentation/007FastSAM/README.md)|UINT8 混合量化|[1,3,640,640]| [🔗](https://github.com/cqu20160901/FastSAM_onnx_rknn) | ### 其他模型 Other | | Name|Quant Type|Categrory|Input Shape|Model Link| | --- | --- | --- | --- | :---: | :---: | |001|[mediapipe-hand](./Other/001mediapipe-hand/README.md)|UINT8|手势识别|[1,3,256,256]|[🔗](https://huggingface.co/qualcomm/MediaPipe-Hand-Detection) | |002|[PP-OCRv5](./Other/002PP-OCRv5/README.md)|INT16|文字识别|[1,3,320,320]| [🔗](https://huggingface.co/PaddlePaddle/PP-OCRv5_server_det) | |003|[Superpoint](./Other/003Superpoint/README.md)|UINT8|关键点检测|[1,1,480,640]|[🔗](https://huggingface.co/qualcomm/Unet-Segmentation) | |004|[wespeaker](./Other/004wespeaker/README.md)|INT16|说话人识别|[1,1024,80]|[🔗](https://huggingface.co/Wespeaker/wespeaker-voxceleb-resnet34-LM) | |005|[GTE](./Other/005GTE/README.md)|INT16|语言文本表示|int64[4,11]| [🔗](https://github.com/hkchengrex/Cutie) | |006|[whisper-tiny](./Other/006whisper-tiny/README.md)|INT16/fp16|语音识别|[1,80,3000]| [🔗](https://huggingface.co/openai/whisper-tiny) | |008|[InsightFace](./Other/008InsightFace/README.md)|UINT8|人脸检测|[1,3,640,640]| [🔗](https://github.com/deepinsight/insightface) | |009|[cutie](./Other/009cutie/README.md)|UINT8|视频图像分割|[1,3,480,864]|[🔗](https://github.com/hkchengrex/Cutie) | ## 四、常见问题 #### Question1: 运行NPU模型部署代码 sample.py 时,找不到 *.mtnn 文件 针对常用的模型,提供部署NPU模型的 sample.py 脚本,方便开发者开箱即用。运行 sample.py 需要指定 *.mtnn 模型的路径。 运行`mtc --config ./mtc_config.yaml`后,会在`/opt/m1000-mtc-toolkit/bin/baselib/data/net_data/onnx/`路径下,生成名为 mtc_config.yaml 中 Name 的文件夹,在该文件夹下的`./mtc/dump_npu_files/*_export_data/`中的 *.mtnn 文件,即为可在NPU上运行的模型。 方便起见,可将该文件复制到 sample.py 的同级路径下,运行 sample.py 。 #### Question2: 如何查看 *.mtnn 模型的网络结构 *.mtnn 文件是最终在NPU上运行的模型,并不能直接查看网络结构。可以通过查看在同一路径生成的 中间格式 *.mtnnir 文件,查看网络结构。 我们提供可查看 *.mtnnir 文件的 Netron-MTNN 工具,并提供 [Linux_arm64版安装包](https://moorethreads-ai-soc.tos-cn-beijing.volces.com/npu_tools/netron-mtnn/linux_arm64/netron-mtnn_8.2.2-r20250930152403+d17c14b7_arm64.deb) 和 [windows_x64版安装包](https://moorethreads-ai-soc.tos-cn-beijing.volces.com/npu_tools/netron-mtnn/windows_x64/Netron-MTNN_Setup_8.2.2.exe) #### Question3: 如何快速测试 NPU 模型的推理性能 请查看[NPU模型的推理性能测试](./doc/performace-test.md)。 #### Question4: export.py 导出 model.onnx 时,生成 model.onnx.data。mtc 显示报错 [Result] Failed: mobilenetv1: Compiler import or dump failed - object of type 'int' has no len() 本项目中使用`torch.onnx.export`导出onnx模型,部分情况下会导出 包含模型网络图信息的 model.onnx 文件和对应的权重文件 model.onnx.data,该情况下使用`mtc --config ./mtc_config.yaml` 时候会报错 [Result] Failed: mobilenetv1: Compiler import or dump failed - object of type 'int' has no len()。 部分情况下使用 dynamo 导出模型也有相同报错。 **解决方法一(推荐)**:使用低版本的 pytorch 如 `pip3 install torch==2.8.0 torchvision==0.23.0` **解决方法二**:禁用dynamo `dynamo=False`,`external_data=False`,例如 ```python torch.onnx.export( model, dummy_input, onnx_model_path, input_names=input_names, output_names=output_names, dynamic_axes=None, dynamo=False, # 禁用dynamo external_data= False, # 禁止将权重保存为外部文件 opset_version=14 ) ```