onnx / onnx-tensorflow

Tensorflow Backend for ONNX
Other
1.27k stars 296 forks source link

Failed to convert Pytorch MASKRCNN_RESNET50_FPN model to TensorFlow from ONNX #1056

Open mmoghadam1 opened 1 year ago

mmoghadam1 commented 1 year ago

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