You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TL;DR: I believe grid_sample is being converted incorrectly, plus it can be made much smaller in size and ~5x faster.
So I went on a search for a better Tensorflow substitute of grid_sample, found some interesting stuff here: #426
The bug
The problem occurs with padding_mode='zero' when pixel index goes out of image bounds by less than a whole pixel. Consider this one-dimensional example:
Let x = -0.4 O[x] = I[x0]*0.6 + I[x1]*0.4, where x0 = -1, x1 = 0, and I[-1] = 0 as an out-of-bounds pixel.
Instead, the current code sets the entire O[x] to 0.
I think the best method to do this right is to zero-pad input image by one pixel to each side and add 1 to all pixel indices.
The expensive post-processing phase becomes unnecessary.
Broken TFLiteConverter
The way Tensorflow converts gather_nd to TFLite is completely broken. Not only is it offensively slow, it also adds this suspicious Concatenation op with a massive tensor of zeros inside.
But 1D gather seems to be alright, so that's what I ended up using.
Right now, I am concentrating on creating my own high precision model. (Work not related to converters)
I will apply it when I have more time in my private life.
Issue Type
Others
OS
Linux
onnx2tf version number
1.18.14
onnx version number
onnxruntime version number
onnxsim (onnx_simplifier) version number
tensorflow version number
2.14
Download URL for ONNX
Parameter Replacement JSON
-
Description
TL;DR: I believe
grid_sample
is being converted incorrectly, plus it can be made much smaller in size and ~5x faster.So I went on a search for a better Tensorflow substitute of
grid_sample
, found some interesting stuff here: #426The bug
The problem occurs with
padding_mode='zero'
when pixel index goes out of image bounds by less than a whole pixel. Consider this one-dimensional example:Let
x = -0.4
O[x] = I[x0]*0.6 + I[x1]*0.4
, wherex0 = -1
,x1 = 0
, andI[-1] = 0
as an out-of-bounds pixel.Instead, the current code sets the entire
O[x]
to 0.I think the best method to do this right is to zero-pad input image by one pixel to each side and add 1 to all pixel indices.
The expensive post-processing phase becomes unnecessary.
Broken TFLiteConverter
The way Tensorflow converts
gather_nd
to TFLite is completely broken. Not only is it offensively slow, it also adds this suspiciousConcatenation
op with a massive tensor of zeros inside.But 1D
gather
seems to be alright, so that's what I ended up using.Full code:
https://github.com/AlexanderLutsenko/nobuco/blob/aa4745e6abb1124d90f7d3ace6d282f923f08a40/nobuco/node_converters/grid_sampling.py#L38
Correctness tests:
https://github.com/AlexanderLutsenko/nobuco/blob/aa4745e6abb1124d90f7d3ace6d282f923f08a40/examples/grid_samplers.py
Benchmark results, Snapdragon 662:
The text was updated successfully, but these errors were encountered: