010-61934861

首页 > Model Zoo > Resnet50-Pytorch
Resnet50-Pytorch
视觉 cv
2024-01-05 | 2150人看过
模型信息

Resnet(Residual Network, 残差网络) 系列网络是一种在图像分类中广泛使用的深度卷积神经网络,同时也作为计算机视觉任务主干经典神经网络的一部分。典型的resnet网络有resnet50, resnet101等。

论文:[《Deep Residual Learning for Image Recognition》](https://arxiv.org/abs/1512.03385)

开源模型链接:https://github.com/pytorch/vision/blob/v0.11.0/torchvision/models/resnet.py

数据集(ImageNet):http://www.image-net.org/

资源准备

  1. 数据集资源下载

    ImageNet是一个不可用于商业目的的数据集,必须通过教育网邮箱注册登录后下载, 请前往官方自行下载ImageNet

  2. 模型资源下载

    下载resnet50 pytorch权重

  3. 清微github modelzoo仓库下载

    git clone https://github.com/tsingmicro-toolchain/ts.knight-modelzoo.git

Knight环境准备

  1. 联系清微智能获取Knight工具链版本包 ReleaseDeliverables/ts.knight-x.x.x.x.tar.gz。下面以ts.knight-2.0.0.4.tar.gz为例演示。

  2. 检查docker环境

    默认服务器中已安装docker(版本>=19.03), 如未安装可参考文档ReleaseDocuments/《TS.Knight-使用指南综述_V1.4.pdf》。

     docker -v
  3. 加载镜像

     docker load -i ts.knight-2.0.0.4.tar.gz
  4. 启动docker容器

     docker run -v ${localhost_dir}/ts.knight-modelzoo:/ts.knight-modelzoo -it ts.knight:2.0.0.4 /bin/bash

    localhost_dir为宿主机目录。

快速体验

在docker 容器内运行以下命令:

cd /ts.knight-modelzoo/pytorch/builtin/cv/classification/
sh resnet50/scripts/run.sh

模型移植流程

1. 量化

  • 模型准备

    如上述"Knight环境准备"章节所述,准备好resnet50 pytorch权重文件。

  • 量化数据准备

    在数据集中选200张图片作为量化校准数据集, 通过命令行参数-i 200指定图片数量,-d指定数据集路径。

  • 模型转换函数、推理函数准备

    已提供量化依赖的模型转换和推理函数py文件: /ts.knight-modelzoo/pytorch/builtin/cv/classification/resnet50/src/resnet50.py

  • 执行量化命令

    在容器内执行如下量化命令,生成量化后的文件 resnet50_quantize.onnx 存放在 -s 指定输出目录。

    Knight --chip TX5368AV200 quant onnx -m resnet50 
        -w /ts.knight-modelzoo/pytorch/builtin/cv/classification/resnet50/weight/resnet50-0676ba61.pth 
        -f pytorch 
        -uds /ts.knight-modelzoo/pytorch/builtin/cv/classification/resnet50/src/resnet50.py 
        -if infer_imagenet_benchmark 
        -s ./tmp/resnet50 
        -d /ts.knight-modelzoo/pytorch/builtin/cv/classification/resnet50/data/imagenet/images/val 
        -bs 1 -i 200

2. 编译

Knight --chip TX5368AV200 rne-compile --onnx resnet50_quantize.onnx --outpath resnet50_example/compile_result

3. 仿真

#准备bin数据
python3 make_resnet_input_bin.py.py  
#仿真
Knight --chip TX5368A rne-sim --input input.bin --weight _quantize_r.weight --config  _quantize_r.cfg --outpath resnet50_example

4. 性能分析

Knight --chip TX5368A rne-profiling --weight  _r.weight --config  _r.cfg --outpath  resnet50_example/

支持芯片情况

芯片系列是否支持
TX2311x支持
TX232不支持
TX510x支持
TX5368x_TX5339x_TX5335x支持
TX5215x_TX5239x200_TX5239x220_TX5239x300支持
TX5112x_TX5239x201支持
TX5336x_TX5356x支持

版本说明

2023/11/23 第一版


发表评论
全部评论(0)