xavier nx建立RNN层失败问题

free-jdx 2021-06-01 18:04:54 5535
1. 前言

已经成功构建了X86上的TRT模型,
但在ARM64 (NX)上构建TRT模型失败。

错误如下

GRU_75: inputs to IRecurrenceLayer mismatched
Builder failed while analyzing shapes.

X86 Config:
TensorRT version: 7.2.3.4

ARM64 config:
TensorRt version: 7.1.3.4

Xavier NX 软件版本JetPack 4.5

2. 尝试其他网络、

已经使用“torch.onnx.export”导出了ONNX
已经使用PyTorch、OnnxRuntime和TensorRT完成了推理。
PyTorch和OnnxRuntime给出了相同的结果,而TensorRT则没有。

觉得ONNX的TrtEngine有问题。
我还有其他的分割模型,载入很好,但结果是不相似的。
我已经尝试了polygraphy分割模型,Pytorch和OnnRuntime给出相同的结果,
但TRT引擎不是。

3. 升级nvonnxparser

对于JetPack 4.5.1环境,可以将nvonnxparser升级到v7.2来修复这个问题。
以下是具体的操作步骤:

Install cmake-3.13.5

$ sudo apt-get install -y protobuf-compiler libprotobuf-dev openssl libssl-dev libcurl4-openssl-dev
$ wget https://github.com/Kitware/CMake/releases/download/v3.13.5/cmake-3.13.5.tar.gz
$ tar xvf cmake-3.13.5.tar.gz
$ cd cmake-3.13.5/
$ ./bootstrap --system-curl
$ make -j$(nproc)
$ echo 'export PATH='${PWD}'/bin/:$PATH' >> ~/.bashrc
$ source ~/.bashrc

Build onnx-tensorrt

$ git clone https://github.com/onnx/onnx-tensorrt.git
$ cd onnx-tensorrt/
$ git submodule update --init --recursive
$ mkdir build && cd build
$ cmake ../
$ make -j

$ sudo mv /usr/lib/aarch64-linux-gnu/libnvonnxparser.so.7.1.3 libnvonnxparser.so.7.1.3_bk
$ sudo cp libnvonnxparser.so.7.2.2 /usr/lib/aarch64-linux-gnu/libnvonnxparser.so.7.2.2

$ sudo rm /usr/lib/aarch64-linux-gnu/libnvonnxparser.so.7
$ sudo ln -s /usr/lib/aarch64-linux-gnu/libnvonnxparser.so.7.2.2 /usr/lib/aarch64-linux-gnu/libnvonnxparser.so.7
$ sudo ldconfig

实际上,在X86_64 Ubuntu上使用TensorRT 8.0+CUDA 11.3解决了所有的问题。

根源在于onnx解析器,而不是TensorRT库本身。
为了兼容性,您仍然需要使用TensorRT v7.1.3。
但是升级ONNX解析器可以解决这个问题

4.更新完测试

在ARM64-NX上更新完后解发现问题
TensorRT 7.1.3通过JetPack 4.5.1安装
Onnx-Parser按照指令安装
问题如下:

home/onnx-tensorrt/onnx2trt_utils.cpp:291: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
/home/onnx-tensorrt/ModelImporter.cpp:703: While parsing node number 37 [Resize -> "300"]:
/home/onnx-tensorrt/ModelImporter.cpp:704: --- Begin node ---
/home/onnx-tensorrt/ModelImporter.cpp:705: input: "295"
input: "299"
input: "526"
output: "300"
name: "Resize_37"
op_type: "Resize"
attribute {
  name: "coordinate_transformation_mode"
  s: "align_corners"
  type: STRING
}
attribute {
  name: "cubic_coeff_a"
  f: -0.75
  type: FLOAT
}
attribute {
  name: "mode"
  s: "linear"
  type: STRING
}
attribute {
  name: "nearest_mode"
  s: "floor"
  type: STRING
}

/home/onnx-tensorrt/ModelImporter.cpp:706: --- End node ---
/home/onnx-tensorrt/ModelImporter.cpp:709: ERROR: /home/onnx-tensorrt/builtin_op_importers.cpp:3074 In function importResize:
[8] Assertion failed: (transformationMode == "asymmetric" || transformationMode == "pytorch_half_pixel" || transformationMode == "half_pixel") && "TensorRT only supports half pixel, pytorch half_pixel, and asymmetric tranformation mode for linear resizes when scales are provided!"
kError: Assertion failed: (transformationMode == "asymmetric" || transformationMode == "pytorch_half_pixel" || transformationMode == "half_pixel") && "TensorRT only supports half pixel, pytorch half_pixel, and asymmetric tranformation mode for linear resizes when scales are provided!"
Network must have at least one output
Network validation failed.
5. 解决思路
Assertion failed: (transformationMode == “half_pixel” || transformationMode == “pytorch_half_pixel” || transformationMode == “align_corners”) && “TensorRT only supports half_pixel, pytorch_half_pixel, and align_corners transofmration modes for linear resizes when sizes are provided!”

以上错误是由一个不支持的操作引起的:调整大小+线性插值+非对称模式。

    //    alignCorners = 0: HALF_PIXEL
    //    alignCorners = 1: ASYMMETRIC
    else
    {
        if (mode == "nearest")
        {
            ASSERT(transformationMode == "asymmetric" && "TensorRT only supports asymmetric tranformation mode for nearest neighbor resizes when scales are provided!",ErrorCode::kUNSUPPORTED_NODE);
        }
        else if (mode == "linear")
        {

            ASSERT((transformationMode == "asymmetric" || transformationMode == "pytorch_half_pixel" || transformationMode == "half_pixel") && "TensorRT only supports half pixel, pytorch half_pixel, and asymmetric tranformation mode for linear resizes when scales are provided!", ErrorCode::kUNSUPPORTED_NODE);

            if (transformationMode == "asymmetric")
            {
                layer->setAlignCorners(true);
            }
        }
    }
}

// For opset 10 resize, the only supported mode is asymmetric resize with scales.

else

增加更多的插值支持的调整层。
目前可以将Resize模式更新为最接近跳过此错误的模式。

更新也可以通过ONNX graphsurgeon API完成。
增加更多的插值支持的调整层。
目前可以将Resize模式更新为最接近跳过此错误的模式。

更新也可以通过ONNX graphsurgeon API完成。

import onnx_graphsurgeon as gs
import onnx
import numpy as np

graph = gs.import_onnx(onnx.load("model.onnx"))
node = [node for node in graph.nodes if node.op == "Resize"]
for n in node:
    n.attrs['mode'] = 'nearest'

onnx.save(gs.export_onnx(graph), "updated_model.onnx")
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
free-jdx
红包 95 6 评论 打赏
评论
0个
内容存在敏感词
手气红包
    易百纳技术社区暂无数据
相关专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
free-jdx
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区