onnx / onnx-tensorflow

Tensorflow Backend for ONNX
Other
1.28k stars 296 forks source link

NotImplementedError: StridedSlice version 1 is not implemented. #352

Open Rathna21 opened 5 years ago

Rathna21 commented 5 years ago

While I try to export a tensorflow model to onnx based on the suggestions in page: I am getting the above issue from both CLI conversion or through program conversion.

I installed onnx and onnx-tf from source.

My python script:

from tensorflow.core.framework import graph_pb2

from onnx_tf.frontend import tensorflow_graph_to_onnx_model from onnx_tf.pb_wrapper import TensorflowGraph

graph_def = graph_pb2.GraphDef() with open("frozen.pb", "rb") as f: # load tf graph def graph_def.ParseFromString(f.read()) output = TensorflowGraph.get_output_node_names( graph_def) # get output node names

model = tensorflow_graph_to_onnx_model(graph_def=graph_def, output=output) # convert tf graph to onnx model with open("output.onnx", 'wb') as f: f.write(model.SerializeToString())

Could you please release a version that resolves StridedSlice error ?

fumihwh commented 5 years ago

@Rathna21

from onnx import defs

print(defs.has("DynamicSlice"))

Is the result True?

Rathna21 commented 5 years ago

@fumihwh ,

I tried the above code and it results "False".

hondaathma commented 5 years ago

Check this out: https://github.com/onnx/onnx-tensorflow/issues/339#issuecomment-455373340

fumihwh commented 5 years ago

@Rathna21 Your onnx is outdated. Reinstall from source could solve this.

git clean -xvf
pip install .

cc: @hondaathma

dipayan90 commented 5 years ago

@fumihwh I Installed it from the latest source and I do see True for print(defs.has("DynamicSlice")) .

However I still get the same error NotImplementedError: StridedSlice version 1 is not implemented. .

Here is my model : model

Here is what I am trying to do: onnx_model = tensorflow_graph_to_onnx_model(graph_def, "dense_1/Softmax")

Error Stacktrace:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-29-e397cacb1aae> in <module>()
      1 onnx_model = tensorflow_graph_to_onnx_model(graph_def,
----> 2                                      "dense_1/Softmax")
      3 
      4 with open("fashion_mnist.onnx", 'wb') as f:
      5   f.write(model.SerializeToString())

~/.conda/envs/nonrootenv/lib/python3.6/site-packages/onnx_tf/frontend.py in tensorflow_graph_to_onnx_model(cls, graph_def, output, opset, producer_name, graph_name, ignore_unimplemented, optimizer_passes)
    173 
    174     onnx_graph = cls.tensorflow_graph_to_onnx_graph(
--> 175         graph_def, output_nodes, opset, graph_name, ignore_unimplemented)
    176     onnx_model = make_model(
    177         onnx_graph, producer_name=producer_name, opset_imports=opset_imports)

~/.conda/envs/nonrootenv/lib/python3.6/site-packages/onnx_tf/frontend.py in tensorflow_graph_to_onnx_graph(cls, graph_def, output, opset, name, ignore_unimplemented)
     98               consts=onnx_graph.consts,
     99               node_dict=dict(node_tup),
--> 100               data_type_cast_map=onnx_graph.data_type_cast_map)
    101         else:
    102           exception.OP_UNIMPLEMENTED_EXCEPT(

~/.conda/envs/nonrootenv/lib/python3.6/site-packages/onnx_tf/handlers/frontend_handler.py in handle(cls, node, **kwargs)
     39   @classmethod
     40   def handle(cls, node, **kwargs):
---> 41     return super(FrontendHandler, cls).handle(node, **kwargs)
     42 
     43   @classmethod

~/.conda/envs/nonrootenv/lib/python3.6/site-packages/onnx_tf/handlers/handler.py in handle(cls, node, **kwargs)
     59       cls.args_check(node, **kwargs)
     60       return ver_handle(node, **kwargs)
---> 61     exception.OP_UNIMPLEMENTED_EXCEPT(node.op_type, cls.SINCE_VERSION)
     62     return None
     63 

~/.conda/envs/nonrootenv/lib/python3.6/site-packages/onnx_tf/common/exception.py in __call__(self, op, version, domain)
     29     if IGNORE_UNIMPLEMENTED:
     30       self._func = warnings.warn
---> 31     super(OpUnimplementedException, self).__call__(op, version, domain)
     32 
     33   def get_message(self, op, version=None, domain=None):

~/.conda/envs/nonrootenv/lib/python3.6/site-packages/onnx_tf/common/exception.py in __call__(self, *args, **kwargs)
     11   def __call__(self, *args, **kwargs):
     12     if inspect.isclass(self._func) and issubclass(self._func, Exception):
---> 13       raise self._func(self.get_message(*args, **kwargs))
     14     elif callable(self._func):
     15       self._func(self.get_message(*args, **kwargs))

NotImplementedError: StridedSlice version 1 is not implemented.
fumihwh commented 5 years ago

@dipayan90 I can't even parse your pbtxt to graph_def.

dipayan90 commented 5 years ago

@fumihwh I am not sure why you are not able to parse the graph_def. I am essentially trying to get the fashion_mnist example converted to onnx. Its just few lines of code to make the model itself.


import tensorflow as tf
from tensorflow import keras
import numpy as np
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
train_images = train_images / 255.0
test_images = test_images / 255.0
model = keras.Sequential([
    keras.layers.Flatten(input_shape=(28, 28)),
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer=tf.train.AdamOptimizer(), 
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
model.fit(train_images, train_labels, epochs=5)
graph = keras.backend.get_session().graph
print(graph)
graph_def = graph.as_graph_def()
print(graph_def)
from onnx_tf.frontend import tensorflow_graph_to_onnx_model
onnx_model = tensorflow_graph_to_onnx_model(graph_def,
                                     "dense_1/Softmax")
with open("fashion_mnist.onnx", 'wb') as f:
  f.write(model.SerializeToString())
dipayan90 commented 5 years ago

@fumihwh Also here is a notebook showing the error: google_colab_link