PINTO0309 / onnx2tf

Self-Created Tools to convert ONNX files (NCHW) to TensorFlow/TFLite/Keras format (NHWC). The purpose of this tool is to solve the massive Transpose extrapolation problem in onnx-tensorflow (onnx-tf). I don't need a Star, but give me a pull request.
MIT License
712 stars 73 forks source link

Feature/babiking/grid sampler #480

Closed babiking closed 1 year ago

babiking commented 1 year ago

1. Content and background

official tensorflow doesn't support GridSample op. Customer implementation of GridSample outputs a large tflite model with slow inference.

batched_grid_sample.onnx.zip

2. Summary of corrections

[1] use "broadcast" attribute and batched tf.gather_nd to generate bilinear interpolate items, to reduce intermediate tf ops. [2] use tf.clip_by_value to avoid conversion errors when H or W is 1

3. Before/After (If there is an operating log that can be used as a reference)

Before: please refer to https://github.com/PINTO0309/onnx2tf/issues/426 After: input size: N=32, C=16, H_in=32, W_in=64, H_out=48, W_out=54 4.0K grid_sample_reproduction.onnx 660K grid_sample_reproduction_float32.tflite

CPU inference elapsed runtime pytorch: 0.0082 sec onnx: 0.0255 sec tflite: 0.0865 sec

4. Issue number (only if there is a related issue)

426