Torch 1.7.0 转onnx转tensorRT:cond.is_weights() && cond.weights().count() == 1 && \”If condition must…

有个模型使用torch1.7.0转tensorRT的时候报错:

1
In node -1 (importIf): UNSUPPORTED_NODE: Assertion failed: cond.is_weights() && cond.weights().count() == 1 && "If condition must be a initializer!"

仔细看一下,错误是发生在importIf,即if节点,可是我forward函数里没有写任何判断,研究了一下转onnx的输出,发现问题出自squeeze()函数,torch1.7版本在onnx里加了一个判断操作,判断要squeeze的维度是不是1:

squeeze

解决:Torch降级到1.6.0