{"action":"opened","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/3903","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/3903/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/3903/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/3903/events","html_url":"https://github.com/tensorflow/tensorflow/issues/3903","id":171923163,"number":3903,"title":"conversion to graph_def lose tensor shapes","user":{"login":"gauravgupta22","id":17435125,"avatar_url":"https://avatars.githubusercontent.com/u/17435125?v=3","gravatar_id":"","url":"https://api.github.com/users/gauravgupta22","html_url":"https://github.com/gauravgupta22","followers_url":"https://api.github.com/users/gauravgupta22/followers","following_url":"https://api.github.com/users/gauravgupta22/following{/other_user}","gists_url":"https://api.github.com/users/gauravgupta22/gists{/gist_id}","starred_url":"https://api.github.com/users/gauravgupta22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gauravgupta22/subscriptions","organizations_url":"https://api.github.com/users/gauravgupta22/orgs","repos_url":"https://api.github.com/users/gauravgupta22/repos","events_url":"https://api.github.com/users/gauravgupta22/events{/privacy}","received_events_url":"https://api.github.com/users/gauravgupta22/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-18T15:01:38Z","updated_at":"2016-08-18T15:01:38Z","closed_at":null,"body":"If i convert a tensorflow model to graph_def using\r\n`tf.get_default_graph().as_graph_def()`\r\nAnd later import it again, i lose the information regarding the tensor shapes\r\n\r\n### Code\r\n```python\r\nimport tensorflow as tf\r\n\r\n# import any tensorflow model\r\nnet = __import__ ('mynet')\r\nimages = tf.placeholder(tf.float32, [32,28,28,3])\r\nnet = getattr(net, 'LeNet')({'data': images})\r\n\r\n# iterate through the graph\r\ngraph = tf.get_default_graph()\r\nfor i in graph.get_operations():\r\n\tprint i.name\r\n\tprint 'OUTPUTS ',\r\n\tfor j in i.outputs:\r\n\t\tprint j.get_shape(),\r\n\tprint \r\n\r\nprint \"*************** CONVERT MODEL TO GRAPH_DEF AND IMPORT AGAIN ***************\"\r\n\r\n# Graph as graph_def\r\ngraph_def = tf.get_default_graph().as_graph_def()\r\n\r\n# reset everything\r\ntf.reset_default_graph()\r\n\r\n# Import the graph_def\r\ntf.import_graph_def(graph_def,name='')\r\n\r\n# iterate through the graph again\r\ngraph = tf.get_default_graph()\r\nfor i in graph.get_operations():\r\n\tprint i.name\r\n\tprint 'OUTPUTS ',\r\n\tfor j in i.outputs:\r\n\t\tprint j.get_shape(),\r\n\tprint\r\n```\r\n### Output\r\n```\r\nPlaceholder\r\nOUTPUTS  (32, 28, 28, 3)\r\nconv1/weights\r\nOUTPUTS  (5, 5, 3, 20)\r\nconv1/weights/Initializer/random_uniform/shape\r\nOUTPUTS  (4,)\r\nconv1/weights/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nconv1/weights/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nconv1/weights/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (5, 5, 3, 20)\r\nconv1/weights/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nconv1/weights/Initializer/random_uniform/mul\r\nOUTPUTS  (5, 5, 3, 20)\r\nconv1/weights/Initializer/random_uniform\r\nOUTPUTS  (5, 5, 3, 20)\r\nconv1/weights/Assign\r\nOUTPUTS  (5, 5, 3, 20)\r\nconv1/weights/read\r\nOUTPUTS  (5, 5, 3, 20)\r\nconv1/Conv2D\r\nOUTPUTS  (32, 24, 24, 20)\r\nconv1/biases\r\nOUTPUTS  (20,)\r\nconv1/biases/Initializer/random_uniform/shape\r\nOUTPUTS  (1,)\r\nconv1/biases/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nconv1/biases/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nconv1/biases/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (20,)\r\nconv1/biases/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nconv1/biases/Initializer/random_uniform/mul\r\nOUTPUTS  (20,)\r\nconv1/biases/Initializer/random_uniform\r\nOUTPUTS  (20,)\r\nconv1/biases/Assign\r\nOUTPUTS  (20,)\r\nconv1/biases/read\r\nOUTPUTS  (20,)\r\nconv1/BiasAdd\r\nOUTPUTS  (32, 24, 24, 20)\r\npool1\r\nOUTPUTS  (32, 12, 12, 20)\r\nconv2/weights\r\nOUTPUTS  (5, 5, 20, 50)\r\nconv2/weights/Initializer/random_uniform/shape\r\nOUTPUTS  (4,)\r\nconv2/weights/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nconv2/weights/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nconv2/weights/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (5, 5, 20, 50)\r\nconv2/weights/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nconv2/weights/Initializer/random_uniform/mul\r\nOUTPUTS  (5, 5, 20, 50)\r\nconv2/weights/Initializer/random_uniform\r\nOUTPUTS  (5, 5, 20, 50)\r\nconv2/weights/Assign\r\nOUTPUTS  (5, 5, 20, 50)\r\nconv2/weights/read\r\nOUTPUTS  (5, 5, 20, 50)\r\nconv2/Conv2D\r\nOUTPUTS  (32, 8, 8, 50)\r\nconv2/biases\r\nOUTPUTS  (50,)\r\nconv2/biases/Initializer/random_uniform/shape\r\nOUTPUTS  (1,)\r\nconv2/biases/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nconv2/biases/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nconv2/biases/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (50,)\r\nconv2/biases/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nconv2/biases/Initializer/random_uniform/mul\r\nOUTPUTS  (50,)\r\nconv2/biases/Initializer/random_uniform\r\nOUTPUTS  (50,)\r\nconv2/biases/Assign\r\nOUTPUTS  (50,)\r\nconv2/biases/read\r\nOUTPUTS  (50,)\r\nconv2/BiasAdd\r\nOUTPUTS  (32, 8, 8, 50)\r\npool2\r\nOUTPUTS  (32, 4, 4, 50)\r\nip1/Reshape/shape\r\nOUTPUTS  (2,)\r\nip1/Reshape\r\nOUTPUTS  (32, 800)\r\nip1/weights\r\nOUTPUTS  (800, 500)\r\nip1/weights/Initializer/random_uniform/shape\r\nOUTPUTS  (2,)\r\nip1/weights/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nip1/weights/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nip1/weights/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (800, 500)\r\nip1/weights/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nip1/weights/Initializer/random_uniform/mul\r\nOUTPUTS  (800, 500)\r\nip1/weights/Initializer/random_uniform\r\nOUTPUTS  (800, 500)\r\nip1/weights/Assign\r\nOUTPUTS  (800, 500)\r\nip1/weights/read\r\nOUTPUTS  (800, 500)\r\nip1/biases\r\nOUTPUTS  (500,)\r\nip1/biases/Initializer/random_uniform/shape\r\nOUTPUTS  (1,)\r\nip1/biases/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nip1/biases/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nip1/biases/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (500,)\r\nip1/biases/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nip1/biases/Initializer/random_uniform/mul\r\nOUTPUTS  (500,)\r\nip1/biases/Initializer/random_uniform\r\nOUTPUTS  (500,)\r\nip1/biases/Assign\r\nOUTPUTS  (500,)\r\nip1/biases/read\r\nOUTPUTS  (500,)\r\nip1/ip1/MatMul\r\nOUTPUTS  (32, 500)\r\nip1/ip1/BiasAdd\r\nOUTPUTS  (32, 500)\r\nip1/ip1\r\nOUTPUTS  (32, 500)\r\nip2/weights\r\nOUTPUTS  (500, 10)\r\nip2/weights/Initializer/random_uniform/shape\r\nOUTPUTS  (2,)\r\nip2/weights/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nip2/weights/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nip2/weights/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (500, 10)\r\nip2/weights/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nip2/weights/Initializer/random_uniform/mul\r\nOUTPUTS  (500, 10)\r\nip2/weights/Initializer/random_uniform\r\nOUTPUTS  (500, 10)\r\nip2/weights/Assign\r\nOUTPUTS  (500, 10)\r\nip2/weights/read\r\nOUTPUTS  (500, 10)\r\nip2/biases\r\nOUTPUTS  (10,)\r\nip2/biases/Initializer/random_uniform/shape\r\nOUTPUTS  (1,)\r\nip2/biases/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nip2/biases/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nip2/biases/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (10,)\r\nip2/biases/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nip2/biases/Initializer/random_uniform/mul\r\nOUTPUTS  (10,)\r\nip2/biases/Initializer/random_uniform\r\nOUTPUTS  (10,)\r\nip2/biases/Assign\r\nOUTPUTS  (10,)\r\nip2/biases/read\r\nOUTPUTS  (10,)\r\nip2/ip2/MatMul\r\nOUTPUTS  (32, 10)\r\nip2/ip2\r\nOUTPUTS  (32, 10)\r\nprob\r\nOUTPUTS  (32, 10)\r\n*************** CONVERT MODEL TO GRAPH_DEF AND IMPORT AGAIN ***************\r\nPlaceholder\r\nOUTPUTS  (32, 28, 28, 3)\r\nconv1/weights\r\nOUTPUTS  <unknown>\r\nconv1/weights/Initializer/random_uniform/shape\r\nOUTPUTS  (4,)\r\nconv1/weights/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nconv1/weights/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nconv1/weights/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (5, 5, 3, 20)\r\nconv1/weights/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nconv1/weights/Initializer/random_uniform/mul\r\nOUTPUTS  (5, 5, 3, 20)\r\nconv1/weights/Initializer/random_uniform\r\nOUTPUTS  (5, 5, 3, 20)\r\nconv1/weights/Assign\r\nOUTPUTS  (5, 5, 3, 20)\r\nconv1/weights/read\r\nOUTPUTS  <unknown>\r\nconv1/Conv2D\r\nOUTPUTS  (32, ?, ?, ?)\r\nconv1/biases\r\nOUTPUTS  <unknown>\r\nconv1/biases/Initializer/random_uniform/shape\r\nOUTPUTS  (1,)\r\nconv1/biases/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nconv1/biases/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nconv1/biases/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (20,)\r\nconv1/biases/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nconv1/biases/Initializer/random_uniform/mul\r\nOUTPUTS  (20,)\r\nconv1/biases/Initializer/random_uniform\r\nOUTPUTS  (20,)\r\nconv1/biases/Assign\r\nOUTPUTS  (20,)\r\nconv1/biases/read\r\nOUTPUTS  <unknown>\r\nconv1/BiasAdd\r\nOUTPUTS  (32, ?, ?, ?)\r\npool1\r\nOUTPUTS  (32, ?, ?, ?)\r\nconv2/weights\r\nOUTPUTS  <unknown>\r\nconv2/weights/Initializer/random_uniform/shape\r\nOUTPUTS  (4,)\r\nconv2/weights/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nconv2/weights/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nconv2/weights/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (5, 5, 20, 50)\r\nconv2/weights/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nconv2/weights/Initializer/random_uniform/mul\r\nOUTPUTS  (5, 5, 20, 50)\r\nconv2/weights/Initializer/random_uniform\r\nOUTPUTS  (5, 5, 20, 50)\r\nconv2/weights/Assign\r\nOUTPUTS  (5, 5, 20, 50)\r\nconv2/weights/read\r\nOUTPUTS  <unknown>\r\nconv2/Conv2D\r\nOUTPUTS  (32, ?, ?, ?)\r\nconv2/biases\r\nOUTPUTS  <unknown>\r\nconv2/biases/Initializer/random_uniform/shape\r\nOUTPUTS  (1,)\r\nconv2/biases/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nconv2/biases/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nconv2/biases/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (50,)\r\nconv2/biases/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nconv2/biases/Initializer/random_uniform/mul\r\nOUTPUTS  (50,)\r\nconv2/biases/Initializer/random_uniform\r\nOUTPUTS  (50,)\r\nconv2/biases/Assign\r\nOUTPUTS  (50,)\r\nconv2/biases/read\r\nOUTPUTS  <unknown>\r\nconv2/BiasAdd\r\nOUTPUTS  (32, ?, ?, ?)\r\npool2\r\nOUTPUTS  (32, ?, ?, ?)\r\nip1/Reshape/shape\r\nOUTPUTS  (2,)\r\nip1/Reshape\r\nOUTPUTS  (?, 800)\r\nip1/weights\r\nOUTPUTS  <unknown>\r\nip1/weights/Initializer/random_uniform/shape\r\nOUTPUTS  (2,)\r\nip1/weights/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nip1/weights/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nip1/weights/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (800, 500)\r\nip1/weights/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nip1/weights/Initializer/random_uniform/mul\r\nOUTPUTS  (800, 500)\r\nip1/weights/Initializer/random_uniform\r\nOUTPUTS  (800, 500)\r\nip1/weights/Assign\r\nOUTPUTS  (800, 500)\r\nip1/weights/read\r\nOUTPUTS  <unknown>\r\nip1/biases\r\nOUTPUTS  <unknown>\r\nip1/biases/Initializer/random_uniform/shape\r\nOUTPUTS  (1,)\r\nip1/biases/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nip1/biases/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nip1/biases/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (500,)\r\nip1/biases/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nip1/biases/Initializer/random_uniform/mul\r\nOUTPUTS  (500,)\r\nip1/biases/Initializer/random_uniform\r\nOUTPUTS  (500,)\r\nip1/biases/Assign\r\nOUTPUTS  (500,)\r\nip1/biases/read\r\nOUTPUTS  <unknown>\r\nip1/ip1/MatMul\r\nOUTPUTS  (?, ?)\r\nip1/ip1/BiasAdd\r\nOUTPUTS  (?, ?)\r\nip1/ip1\r\nOUTPUTS  (?, ?)\r\nip2/weights\r\nOUTPUTS  <unknown>\r\nip2/weights/Initializer/random_uniform/shape\r\nOUTPUTS  (2,)\r\nip2/weights/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nip2/weights/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nip2/weights/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (500, 10)\r\nip2/weights/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nip2/weights/Initializer/random_uniform/mul\r\nOUTPUTS  (500, 10)\r\nip2/weights/Initializer/random_uniform\r\nOUTPUTS  (500, 10)\r\nip2/weights/Assign\r\nOUTPUTS  (500, 10)\r\nip2/weights/read\r\nOUTPUTS  <unknown>\r\nip2/biases\r\nOUTPUTS  <unknown>\r\nip2/biases/Initializer/random_uniform/shape\r\nOUTPUTS  (1,)\r\nip2/biases/Initializer/random_uniform/min\r\nOUTPUTS  ()\r\nip2/biases/Initializer/random_uniform/max\r\nOUTPUTS  ()\r\nip2/biases/Initializer/random_uniform/RandomUniform\r\nOUTPUTS  (10,)\r\nip2/biases/Initializer/random_uniform/sub\r\nOUTPUTS  ()\r\nip2/biases/Initializer/random_uniform/mul\r\nOUTPUTS  (10,)\r\nip2/biases/Initializer/random_uniform\r\nOUTPUTS  (10,)\r\nip2/biases/Assign\r\nOUTPUTS  (10,)\r\nip2/biases/read\r\nOUTPUTS  <unknown>\r\nip2/ip2/MatMul\r\nOUTPUTS  (?, ?)\r\nip2/ip2\r\nOUTPUTS  (?, ?)\r\nprob\r\nOUTPUTS  (?, ?)\r\n```\r\n\r\nIt can be clearly seen that the shape of the last tensor (and others as well) in the model was `(32, 10)` and after conversion to graph_def and import again it becomes `(?, ?)`.\r\n\r\nIs there any other way to get output shapes out of any graph_def?\r\n\r\n"}}
{"actor":{"display_login":"gauravgupta22"}}