onnx/onnx-tensorflow

Failed to convert Pytorch MASKRCNN_RESNET50_FPN model to TensorFlow from ONNX

mmoghadam1 opened this issue · 0 comments

Describe the bug

When trying to run inference on a pretrained PyTorch model that has been converted to TensorFlow from ONNX, I get the following error:

ValueError: as_list() is not defined on an unknown TensorShape.

Inference using the onnx model with onnxruntime works fine, it's only when I convert it to TensorFlow that it fails. I've used this same code with other PyTorch models and it works fine, so I'm guessing it's related to the pretrained model.

To Reproduce

Here's a minimal example:

import torch
import torchvision
import onnx
from onnx_tf.backend import prepare

pt_model = torchvision.models.detection.maskrcnn_resnet50_fpn(weights="DEFAULT")
x = torch.randn(1, 3,800,800)
torch.onnx.export(pt_model, x, "torch.onnx")
model = onnx.load('torch.onnx')
tf_rep = prepare(model)
tf_output = tf_rep.run(x)

ONNX model file

https://drive.google.com/file/d/1sw1GhywhFrpeO6zQSaz9hlop1SEnDYG_/view?usp=sharing

Python, ONNX, ONNX-TF, Tensorflow version

  • Python version: 3.9.5
  • ONNX version: 1.13.0
  • ONNX-TF version: 1.10.0
  • Tensorflow version: 2.5.0