文件最后提交记录最后更新时间
init 4 年前
fix link validity Co-authored-by: frozenleaves<914814442@qq.com> # message auto-generated for no-merge-commit merge: !7517 merge master into master fix link validity Created-by: frozenn Commit-by: frozenleaves Merged-by: ascend-robot Description: ## Motivation Please describe the motivation of this PR and the goal you want to achieve through this PR. ## Modification Please briefly describe what modification is made in this PR. ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!75171 个月前
【BugFix】【Pytorch离线推理】ACL接口兼容性修改 4 年前
init 4 年前
init 4 年前
init 4 年前
update ACL_PyTorch/contrib/cv/video_understanding/I3D/i3d_inference.py. 支持 fp163 年前
init 4 年前
init 4 年前
README.md

I3D模型推理指导

1、概述

1.1、模型概述

​ I3D是一种新的基于2D ConvNet 膨胀的双流膨胀3D ConvNet (I3D)。一个I3D网络在RGB输入上训练,另一个在流输入上训练,这些输入携带优化的、平滑的流信息。 模型分别训练了这两个网络,并在测试时将它们的预测进行平均后输出。深度图像分类ConvNets的过滤器和池化内核从2D被扩展为3D,从而可以从视频中学习效果良好的时空特征提取器并改善ImageNet的架构设计,甚至是它们的参数。论文链接

1.2、代码链接

代码链接

branch=master

commit_id=529f4543cb49e7b5b61972653935369bc9c92e70

2、环境说明

无明确要求,以下环境仅供参考:

CANN:5.1.RC1

python:3.8.0

onnx==1.7.0
torch==1.8.0
torchvision==0.9.0
numpy==1.22.3
Pillow==7.2.0
mmcv==1.4.0
scipy==1.8.1

3、获取数据集

首先clone仓库:

git clone https://github.com/open-mmlab/mmaction2.git
git checkout dbf5d59fa592818325285b786a0eab8031d9bc80
cd mmaction2

将acl_net.py放置在mmaction2目录下,将i3d_inference.py放置在tools目录下。

然后在仓库中创建目录。

mkdir -p data/kinetics400

获取标注文件:运行仓库中的tools/data/kinetics/download_backup_annotations.sh.将会在data/kinetics400目录下创建annotations目录。

cd tools/data/kinetics
bash download_backup_annotations.sh kinetics400
cd ../../..

最后获取kinetics400验证集。

数据集 验证集视频
kinetics400 19796

我们使用的 Kinetics400 验证集包含 19796 个视频,用户可以从 验证集视频 下载这些视频。 下载并解压好后,将数据集重命名为videos_val并放置于data/kinetics400目录下。

数据集准备完成。

4、数据预处理

若有另外需求,请参考数据处理。

运行预处理脚本。将对videos_val中的所有视频进行抽帧处理,并将结果放置在data/kinetics400/rawframes_val目录下。本脚本采用Opencv对mp4格式的视频,采用4线程抽取256*256大小的RGB帧,输出格式为jpg。

bash build_rawframes.sh

将generate_labels.py文件放在data/kientics400目录下。运行该脚本获取验证所需要的验证文件。将生成kinetics400_label.txt和kinetics400_val_list_rawframes.txt。kinetics400_val_list_rawframes.txt即为验证时需要的文件。

python generate_labels.py

数据预处理完成。

5、模型转换

首先配置环境变量:

source /usr/local/Ascend/ascend-toolkit/set_env.sh

本节采用的模型输入为:1x10x3x32x256x256.($batch $clip $channel $time $height $width )。选择300I PRO的话batch_size可以设置为1,4,8。

首先在mmaction2目录下创建新目录checkpoints

mkdir checkpoints

然后下载预训练模型:i3d_nl_not_product_r50,在README里选择i3d_nl_dot_product_r50_32x2x1_100e_kinetics400_rgb配置,下载权重文件,并将该权重文件重命名为i3d_nl_dot_product_r50.pth,并保存在checkpoints目录下。

将pth文件转换为om文件。其中,${chip_name}通过npu-smi info获取。

python3 tools/pytorch2onnx.py configs/recognition/i3d/i3d_r50_32x2x1_100e_kinetics400_rgb.py checkpoints/i3d_r50_32x2x1_100e_kinetics400_rgb_20200614-c25ef9a4.pth --shape 1 30 3 32 256 256 --verify --show --output i3d.onnx --opset-version 11
atc --framework=5 --output=./i3d_bs1  --input_format=NCHW  --soc_version=Ascend${chip_name} --model=./i3d.onnx --input_shape="0:1,10,3,32,256,256"

得到i3d_bs1.om。模型转换完成。

6、离线推理

执行脚本:

bash i3d_infer.sh

即可获取top1_acc,top5_acc和mean_acc。

7、精度统计

TOP1 TOP5
300I PRO精度 71.19% 90.21%

8、性能对比

./benchmark.x86_64 -device_id=0 -om_path=./i3d_bs1.om -round=30 -batch_size=1
./benchmark.x86_64 -device_id=0 -om_path=./i3d_bs1.om -round=30 -batch_size=1

GPU:只需要onnx文件。执行脚本。

trtexec --onnx=i3d_nl_dot.onnx --fp16 --shapes=0:1x30x3x32x256x256 --threads
300I PRO 300I PRO_aoe t4 300I PRO_aoe/t4
bs1 4.45 6.15 3.38 1.82
top1 0.7119
top5 0.9021