I have a custom model based on transfer learning (Resnet50). It has 7 classes for image classification. I have used tensorflow-onnx conversion to get a onnx file.
[TRT] 4: [network.cpp::validate::3062] Error Code 4: Internal Error (Network has dynamic or shape inputs, but no optimization profile has been defined.)
[TRT] device GPU, failed to build CUDA engine
[TRT] device GPU, failed to load models/pave/model_1.onnx
[TRT] failed to load models/pave/model_1.onnx
[TRT] imageNet -- failed to initialize.
imagenet: failed to initialize imageNet
Hi @joaquin.bh3, the model was exported with dynamic shapes, but should have static input shapes. It expects ONNX models that were exported from PyTorch like here:
Dang, so I am confused since the imagenet example says other networks can be added using --network including resnet50.
For my case, if I fix the input of my model (which is originally Tensorflow, resnet50, , would I be able to feed it through the imagenet example? or it’s best not to keep trying?
I don’t see in the imagenet.py why it wouldn’t work…
For instance, below is the conversion from h5 to ONNX.
import tf2onnx
import onnxruntime as rt
from tensorflow.keras.models import load_model
import tensorflow as tf
model = load_model('test512.h5')
spec = (tf.TensorSpec((None, 224, 224, 3), tf.float32, name="input"),)
output_path = model.name + ".onnx"
onnx_model, _ = tf2onnx.convert.from_keras(model, input_signature=spec, opset=13)
onnx.save(onnx_model, "model_3.onnx")
I’m not personally familiar with tf2onnx and don’t see in it’s documentation a flag to explicitly force static shapes, but I wonder if you changed the input dims to (1, 224, 224, 3) if that would make static-shaped input as opposed to dynamic. I also found this post:
Thanks very much, Dusty_nv. It did solve that error of dynamic input.
I believe its reading the model and labels but I get a constant 38.8% and a class 0 for any of the pictures or webcam that I test. Any ideas what it could be?
OK, cool that you got past the dynamic shapes. Next, I would check that the pre-processing applies matches what TensorFlow does:
For example, these coefficients for mean pixel subtraction and normalization are the same ones that PyTorch uses. Also check that your model expects NCHW data layout.