ResNet50
ResNet 是由微软研究院提出的里程碑式深度卷积神经网络架构。它通过首创的残差学习(Residual Learning)机制,利用“跳跃连接”完美解决了深层网络难以训练的梯度消失问题,彻底打破了深度学习在模型层数上的限制。
- 核心特点:专注于高精度的图像特征提取与分类任务,其强大的通用特征表达能力使其成为目标检测、语义分割等复杂视觉任务最常用的基石架构(Backbone)。
- 版本说明:本案例采用 ResNet-50 (V1)。作为 ResNet 家族中最具代表性的中坚力量,它由 50 层深度网络组成,采用了高效的瓶颈(Bottleneck)结构。它在计算复杂度和识别准确率之间取得了完美的平衡,是目前工业界兼具高性能与高稳定性、落地应用最广泛的经典视觉模型。
环境配置
需要提前配置好相关环境。
快速开始
下载模型文件
O6 / O6N
cd ai_model_hub_25_Q3/models/ComputeVision/Image_Classification/onnx_resnet_v1_50
wget -O resnet_v1_50.cix https://www.modelscope.cn/models/cix/ai_model_hub_25_Q3/resolve/master/models/ComputeVision/Image_Classification/onnx_resnet_v1_50/resnet_v1_50.cix
模型测试
信息
运行前激活虚拟环境!
O6 / O6N
python3 inference_npu.py
完整转换流程
下载模型文件
Linux PC
cd ai_model_hub_25_Q3/models/ComputeVision/Image_Classification/onnx_resnet_v1_50/model
wget -O resnet50-v1-12.onnx https://www.modelscope.cn/models/cix/ai_model_hub_25_Q3/resolve/master/models/ComputeVision/Image_Classification/onnx_resnet_v1_50/model/resnet50-v1-12.onnx
wget -O resnet50-v1-12-sim.onnx https://www.modelscope.cn/models/cix/ai_model_hub_25_Q3/resolve/master/models/ComputeVision/Image_Classification/onnx_resnet_v1_50/model/resnet50-v1-12-sim.onnx
项目结构
├── cfg
├── datasets
├── inference_npu.py
├── inference_onnx.py
├── model
├── ReadMe.md
├── resnet_v1_50.cix
├── test_data
├── label.txt
├── main.cpp
├── makefile
├── noe_utils
└── Tutorials.ipynb
进行模型量化和转换
Linux PC
cd ..
cixbuild cfg/onnx_resnet_v1_50build.cfg
推送到板端
完成模型转换之后需要将 cix 模型文件推送到板端。
测试主机推理
运行推理脚本
Linux PC
python3 inference_onnx.py --images test_data --onnx_path model/resnet50-v1-12-sim.onnx
模型推理结果
Linux PC
$ python3 inference_onnx.py --images test_data --onnx_path model/resnet50-v1-12-sim.onnx
image path : test_data/ILSVRC2012_val_00024154.JPEG
Ibizan hound, Ibizan Podenco
image path : test_data/ILSVRC2012_val_00021564.JPEG
coucal
image path : test_data/ILSVRC2012_val_00002899.JPEG
rock python, rock snake, Python sebae
image path : test_data/ILSVRC2012_val_00045790.JPEG
Yorkshire terrier
image path : test_data/ILSVRC2012_val_00037133.JPEG
ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus
进行 NPU 部署
运行推理脚本
O6 / O6N
python3 inference_npu.py --images test_data --model_path resnet_v1_50.cix
模型推理结果
O6 / O6N
$ python3 inference_npu.py --images test_data --model_path resnet_v1_50.cix
npu: noe_init_context success
npu: noe_load_graph success
Input tensor count is 1.
Output tensor count is 1.
npu: noe_create_job success
image path : test_data/ILSVRC2012_val_00037133.JPEG
ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus
image path : test_data/ILSVRC2012_val_00021564.JPEG
coucal
image path : test_data/ILSVRC2012_val_00024154.JPEG
Ibizan hound, Ibizan Podenco
image path : test_data/ILSVRC2012_val_00002899.JPEG
rock python, rock snake, Python sebae
image path : test_data/ILSVRC2012_val_00045790.JPEG
Yorkshire terrier
npu: noe_clean_job success
npu: noe_unload_graph success
npu: noe_deinit_context success