{"action":"created","issue":{"url":"https://api.github.com/repos/onnx/onnx-tensorflow/issues/167","repository_url":"https://api.github.com/repos/onnx/onnx-tensorflow","labels_url":"https://api.github.com/repos/onnx/onnx-tensorflow/issues/167/labels{/name}","comments_url":"https://api.github.com/repos/onnx/onnx-tensorflow/issues/167/comments","events_url":"https://api.github.com/repos/onnx/onnx-tensorflow/issues/167/events","html_url":"https://github.com/onnx/onnx-tensorflow/issues/167","id":322798320,"number":167,"title":"Can not use converted ONNX -> TF graph independently [py_func issue]","user":{"login":"nmakhotkin","id":4181806,"avatar_url":"https://avatars2.githubusercontent.com/u/4181806?v=4","gravatar_id":"","url":"https://api.github.com/users/nmakhotkin","html_url":"https://github.com/nmakhotkin","followers_url":"https://api.github.com/users/nmakhotkin/followers","following_url":"https://api.github.com/users/nmakhotkin/following{/other_user}","gists_url":"https://api.github.com/users/nmakhotkin/gists{/gist_id}","starred_url":"https://api.github.com/users/nmakhotkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmakhotkin/subscriptions","organizations_url":"https://api.github.com/users/nmakhotkin/orgs","repos_url":"https://api.github.com/users/nmakhotkin/repos","events_url":"https://api.github.com/users/nmakhotkin/events{/privacy}","received_events_url":"https://api.github.com/users/nmakhotkin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"tjingrant","id":6410074,"avatar_url":"https://avatars1.githubusercontent.com/u/6410074?v=4","gravatar_id":"","url":"https://api.github.com/users/tjingrant","html_url":"https://github.com/tjingrant","followers_url":"https://api.github.com/users/tjingrant/followers","following_url":"https://api.github.com/users/tjingrant/following{/other_user}","gists_url":"https://api.github.com/users/tjingrant/gists{/gist_id}","starred_url":"https://api.github.com/users/tjingrant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjingrant/subscriptions","organizations_url":"https://api.github.com/users/tjingrant/orgs","repos_url":"https://api.github.com/users/tjingrant/repos","events_url":"https://api.github.com/users/tjingrant/events{/privacy}","received_events_url":"https://api.github.com/users/tjingrant/received_events","type":"User","site_admin":false},"assignees":[{"login":"tjingrant","id":6410074,"avatar_url":"https://avatars1.githubusercontent.com/u/6410074?v=4","gravatar_id":"","url":"https://api.github.com/users/tjingrant","html_url":"https://github.com/tjingrant","followers_url":"https://api.github.com/users/tjingrant/followers","following_url":"https://api.github.com/users/tjingrant/following{/other_user}","gists_url":"https://api.github.com/users/tjingrant/gists{/gist_id}","starred_url":"https://api.github.com/users/tjingrant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjingrant/subscriptions","organizations_url":"https://api.github.com/users/tjingrant/orgs","repos_url":"https://api.github.com/users/tjingrant/repos","events_url":"https://api.github.com/users/tjingrant/events{/privacy}","received_events_url":"https://api.github.com/users/tjingrant/received_events","type":"User","site_admin":false}],"milestone":null,"comments":7,"created_at":"2018-05-14T12:37:55Z","updated_at":"2018-05-15T06:08:34Z","closed_at":null,"author_association":"NONE","body":"I am trying to export some ONNX model to Tensorflow and then use it for inference (possibly on another environment). Here is an example of exporting MNIST model:\r\n```python\r\nimport numpy as np\r\nimport onnx\r\nfrom onnx_tf.backend import prepare\r\nimport tensorflow as tf\r\n\r\n\r\nprint('loading onnx model')\r\nonnx_model = onnx.load('train/model.onnx')\r\n\r\nprint('prepare tf model')\r\ntf_rep = prepare(onnx_model)\r\nprint(tf_rep.predict_net)\r\nprint('-----')\r\nprint(tf_rep.predict_net.tensor_dict)\r\n\r\ntest = np.random.rand(1, 1, 28, 28)\r\n\r\nout = tf_rep.run(test)._0\r\nprint(out)\r\n\r\nwith tf.Session() as persisted_sess:\r\n    print(\"load graph\")\r\n    persisted_sess.graph.as_default()\r\n    tf.import_graph_def(tf_rep.predict_net.graph.as_graph_def(), name='')\r\n    # for op in persisted_sess.graph.get_operations():\r\n    #    print(op)\r\n    inp = persisted_sess.graph.get_tensor_by_name(\r\n        tf_rep.predict_net.tensor_dict[tf_rep.predict_net.external_input[0]].name\r\n    )\r\n    out = persisted_sess.graph.get_tensor_by_name(\r\n        tf_rep.predict_net.tensor_dict[tf_rep.predict_net.external_output[0]].name\r\n    )\r\n    res = persisted_sess.run(out, {inp: test})\r\n    print(res)\r\n\r\ntf_rep.export_graph('train/tf.pb')\r\n```\r\n\r\nThe script above executes successfully and the prediction also runs successfully (`res` == `out` here). Now, I am importing the saved model in TF:\r\n```python\r\nimport numpy as np\r\nimport tensorflow as tf\r\nfrom tensorflow.python.platform import gfile\r\n\r\n\r\nname = \"train/tf.pb\"\r\n\r\nwith tf.Session() as persisted_sess:\r\n    print(\"load graph\")\r\n    with gfile.FastGFile(name, 'rb') as f:\r\n        graph_def = tf.GraphDef()\r\n        graph_def.ParseFromString(f.read())\r\n\r\n    persisted_sess.graph.as_default()\r\n    tf.import_graph_def(graph_def, name='')\r\n\r\n    test = np.random.rand(1, 1, 28, 28).astype(np.float32)\r\n\r\n    inp = persisted_sess.graph.get_tensor_by_name('0:0')\r\n    out = persisted_sess.graph.get_tensor_by_name('LogSoftmax:0')\r\n    feed_dict = {inp: test}\r\n\r\n    classification = persisted_sess.run(out, feed_dict)\r\n\r\n```\r\n\r\nAnd now I got the error related to nonexistent PyFuncs:\r\n```\r\n2018-05-14 15:28:36.780899: W tensorflow/core/framework/op_kernel.cc:1198] tensorflow.python.framework.errors_impl.UnknownError: exceptions.KeyError: 'pyfunc_0'\r\n         [[Node: PyFunc = PyFunc[Tin=[DT_FLOAT, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_INT32, DT_STRING], Tout=[DT_FLOAT], token=\"pyfunc_0\", _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"](transpose_2, PyFunc/input_1, PyFunc/input_1, PyFunc/input_3, PyFunc/input_4, PyFunc/input_5, PyFunc/input_6)]]\r\n```\r\nFull log: [https://pastebin.com/0bQeMPTG](https://pastebin.com/0bQeMPTG)\r\nBut at the moment of exporting the model worked fine (see above). I did some investigation on what exact functions are being used in the TF graph: \r\n```\r\n(Pdb) from tensorflow.python.ops import script_ops\r\n(Pdb) script_ops._py_funcs._funcs\r\n{'pyfunc_0': <function py_pool at 0x7f395db05500>, 'pyfunc_1': <function py_pool at 0x7f395dab99b0>}\r\n(Pdb) funcs = script_ops._py_funcs._funcs.values()\r\n(Pdb) func = funcs[0]\r\n(Pdb) func.func_name\r\n'py_pool'\r\n(Pdb) func.func_code\r\n<code object py_pool at 0x7f395fb9deb0, file \"/usr/local/lib/python2.7/dist-packages/onnx_tf/backends/backend_v1.py\", line 94>\r\n(Pdb)\r\n```\r\nSo, I have a question: is this intended that TF graph uses external function from `onnx_tf` package? Or this is simply a bug?\r\nIs there any way to make this model independent of `onnx` and `onnx-tf` packages?\r\n"},"comment":{"url":"https://api.github.com/repos/onnx/onnx-tensorflow/issues/comments/389053523","html_url":"https://github.com/onnx/onnx-tensorflow/issues/167#issuecomment-389053523","issue_url":"https://api.github.com/repos/onnx/onnx-tensorflow/issues/167","id":389053523,"user":{"login":"nmakhotkin","id":4181806,"avatar_url":"https://avatars2.githubusercontent.com/u/4181806?v=4","gravatar_id":"","url":"https://api.github.com/users/nmakhotkin","html_url":"https://github.com/nmakhotkin","followers_url":"https://api.github.com/users/nmakhotkin/followers","following_url":"https://api.github.com/users/nmakhotkin/following{/other_user}","gists_url":"https://api.github.com/users/nmakhotkin/gists{/gist_id}","starred_url":"https://api.github.com/users/nmakhotkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmakhotkin/subscriptions","organizations_url":"https://api.github.com/users/nmakhotkin/orgs","repos_url":"https://api.github.com/users/nmakhotkin/repos","events_url":"https://api.github.com/users/nmakhotkin/events{/privacy}","received_events_url":"https://api.github.com/users/nmakhotkin/received_events","type":"User","site_admin":false},"created_at":"2018-05-15T06:08:33Z","updated_at":"2018-05-15T06:08:33Z","author_association":"NONE","body":"@tjingrant thanks! I'll try today (it is morning for me now) and will write the results here."}}
{"actor":{"display_login":"nmakhotkin"}}