Error when convert dynamic axes ONNX to dynamic axes TFLite 
Hi @ThuyyTran 

Could you please share a toy TFLite model  or TF saved model inorder to reproduce the error. That will help to better investigate the issue.

Thanks. > Hi @ThuyyTran
> 
> Could you please share a toy TFLite model or TF saved model inorder to reproduce the error. That will help to better investigate the issue.
> 
> Thanks.


@pjpratik Here is model: https://drive.google.com/drive/folders/1BUpjHtBOZYD_pqfBvUSQf25y9AMACufd?usp=sharing

 @pjpratik Hi I was able to reproduce this issue. Please find this [gist](https://colab.research.google.com/gist/pjpratik/afd62bad52fa7df3aaa16f81ad3e8bb7/62015.ipynb). Seems to be pytorch->onnx->tflite issue.

@pkgoogle Could you please look into this issue?

Thanks. Hi @ThuyyTran, unfortunately we currently do not support dynamic input shapes and do not plan to in the near future as doing so will have too great of a performance impact to most workflows. https://www.tensorflow.org/lite/guide/inference#run_inference_with_dynamic_shape_model. For dynamic axes, please manually/force these axes to be static and shape your model/data statically before converting to .tflite format and let us know if that works.
 > Hi @ThuyyTran, unfortunately we currently do not support dynamic input shapes and do not plan to in the near future as doing so will have too great of a performance impact to most workflows. https://www.tensorflow.org/lite/guide/inference#run_inference_with_dynamic_shape_model. For dynamic axes, please manually/force these axes to be static and shape your model/data statically before converting to .tflite format and let us know if that works.

Does it mean I can't use dynamic axes for the TFlite model? So what is dynamic input shape and how does it work? @ThuyyTran, correct you can't use dynamic axes for the TFLite model, dynamic input shape means that one or more dimensions of your input data is variable. Dynamic axes defines which dimensions are variable, so if there are dynamic axes -> there is a dynamic input shape. TFLite is currently not designed to convert/handle dynamic input shapes due to the performance costs involved in handling such architectures. Usually there is a way to force your model/data to be statically shaped which makes sense but you'll have to figure it out for your own situation. Common ways include padding/cropping and various forms of extrapolation, interpolation, upsampling or downsampling but it really depends on what you are trying to do. > @ThuyyTran, correct you can't use dynamic axes for the TFLite model, dynamic input shape means that one or more dimensions of your input data is variable. Dynamic axes defines which dimensions are variable, so if there are dynamic axes -> there is a dynamic input shape. TFLite is currently not designed to convert/handle dynamic input shapes due to the performance costs involved in handling such architectures. Usually there is a way to force your model/data to be statically shaped which makes sense but you'll have to figure it out for your own situation. Common ways include padding/cropping and various forms of extrapolation, interpolation, upsampling or downsampling but it really depends on what you are trying to do.

When I run input sample with shape(224x244) by Onnx in step 1 and convert to TFlite. I tested TFLite model with sizes 411x411, 320x320 and it was successful but when I try with size 150x150,  480x480 so got error:
line 917, in invoke
    self._interpreter.Invoke()
RuntimeError: tensorflow/lite/kernels/squeeze.cc:63 current >= 0 && current < input_num_dims && input_dims->data[current] == 1 was not true.Node number 254 (SQUEEZE) failed to prepare. Hi @ThuyyTran, we don't purposely try to limit these workflows so sometimes it does handle dynamic shapes for some ops however because we can't guarantee it works for every case, it is considered not supported, in your case please statically size the input shape for the model (then convert it) and do data preprocessing to force your data into the right shape to feed into the converted model. For example say you choose 224x224 as your static input shape, you would need to upsample the 150x150 image (perhaps interpolate the holes?) and downsample the 480x480 image, before it ever gets to the converted model. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62105">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/62105">No</a>

### 1. System information

- Ubuntu20.04
- Tensorflow: 2.11
- Python: 3.10.8
- Pytorch: 1.12.0

### 2. Code
#### The first convert Pytorch model to Onnx with dynamic input:
    network = 'rSfM120k-tl-resnet50-gem-w'
    state = load_url(PRETRAINED[network], model_dir=os.path.join(get_data_root(), 'networks'))
    net_params = {}
    net_params['architecture'] = state['meta']['architecture']
    net_params['pooling'] = state['meta']['pooling']
    net_params['local_whitening'] = state['meta'].get('local_whitening', False)
    net_params['regional'] = state['meta'].get('regional', False)
    net_params['whitening'] = state['meta'].get('whitening', True)
    net_params['mean'] = state['meta']['mean']
    net_params['std'] = state['meta']['std']
    net_params['pretrained'] = False
    
    net = init_network(net_params)
    net.load_state_dict(state['state_dict'])
    
    if useRmac:
        net.pool = RMAC(3)
    net.cuda()
    net.eval()
    dummy_input = torch.randn(1, 3, 400, 900)
    input_names = [ "actual_input" ]
    output_names = [ "output" ]
    dynamic_axes_dict = { 'actual_input': { 0: 'bs',  2: 'img_x',3: 'img_y'},'Output': { 0: 'bs'}} 
    torch.onnx.export(net,
                     dummy_input,
                     "resnet50.onnx",
                     verbose=False,
                     input_names=input_names,
                     output_names=output_names,
                    dynamic_axes=dynamic_axes_dict,
                     opset_version=12, 
                    )
#### The second convert Onnx model to Tf:
    onnx_path = 'resnet50.onnx'
    onnx_model = onnx.load( onnx_path)
    onnx.checker.check_model(onnx_model)
    tf_path = 'cirtorch_tf_0210_resnet50_withoutNor'
    tf_rep = prepare(onnx_model)  #Prepare TF representation
    tf_rep.export_graph(tf_path)  #Export the model
#### The third convert Tf model to TfLite:
    tf_lite_path = '0210_cirtorch_fl16_resnet50_withoutNor.tflite'
    converter = tf.lite.TFLiteConverter.from_saved_model(tf_path)
    tflite_model  = converter.convert()
    with open(tf_lite_path, 'wb') as f:
        f.write(tflite_model)
#### Test model TfLite with dynamic input:
    tflite_model_path = tf_lite_path
    interpreter = tf.lite.Interpreter(model_path=tflite_model_path,experimental_delegates=[])
    input_details = interpreter.get_input_details()
    output_details = interpreter.get_output_details()
    interpreter.resize_tensor_input(interpreter.get_input_details()[0]['index'],[1,3,200,200])
    input_details = interpreter.get_input_details()
    output_details = interpreter.get_output_details()
    interpreter.allocate_tensors()
    x1 = torch.ones(1,3,200, 200)
    input_data = np.array(x1, dtype=np.float32)
    print(input_data.shape)
    interpreter.set_tensor(input_details[0]['index'], input_data)
    interpreter.invoke()
    output_data = interpreter.get_tensor(output_details[0]['index'])
    print(output_data.shape)
### But I got error when invoke model TFLite:
Traceback (most recent call last):
  File "convertCirtorchFreesizeTFlite.py", line 143, in <module>
    interpreter.invoke()
  File "/home/anlab/anaconda3/envs/bopw/lib/python3.10/site-packages/tensorflow/lite/python/interpreter.py", line 917, in invoke
    self._interpreter.Invoke()
RuntimeError: tensorflow/lite/kernels/squeeze.cc:63 current >= 0 && current < input_num_dims && input_dims->data[current] == 1 was not true.Node number 0 (SQUEEZE) failed to prepare.Node number 144 (IF) failed to prepare.
#### Or
  File "/home/anlab/anaconda3/envs/bopw/lib/python3.10/site-packages/tensorflow/lite/python/interpreter.py", line 917, in invoke
    self._interpreter.Invoke()
RuntimeError: tensorflow/lite/kernels/reshape.cc:85 num_input_elements != num_output_elements (2048 != 4194304)Node number 2 (RESHAPE) failed to invoke.Node number 144 (IF) failed to invoke.
