onnx / keras-onnx

Convert tf.keras/Keras models to ONNX
Apache License 2.0
379 stars 109 forks source link

Missing 'Constant' value of TF opLayer while conversion #515

Closed buddhapuneeth closed 4 years ago

buddhapuneeth commented 4 years ago

I am trying to add 'ReverseV2' operator support in keras-onnx. TF ReverseV2 operator takes axes list as one of the input. This list is missing from the 'operator.raw_operator' in __buildin.py where I am adding the new operator. In the below example I am passing [2] as axes list and in keras-onnx I am able to find a way to read that value.

My model:

import tensorflow as tf
from tensorflow.keras.models import save_model
input = tf.keras.Input(shape=(3, 4), name='input')
s = tf.reverse(input,[2]) #here [1] is the access
model = tf.keras.models.Model(inputs=input, outputs=s)
save_model(model, "reverse.h5")

To debug: Just add new Type ReverseV2 and add below dummy method in __buildin.py

@converter_func(TYPES.ReverseV2)
def convert_tf_reverse(scope, operator, container):
     print("test") #add debug breakpoint here

Visualization:

Screen Shot 2020-06-04 at 4 47 22 PM
buddhapuneeth commented 4 years ago

Nevermind. I got it using _cal_tensor_value(node.inputs[1])