{"action":"created","issue":{"url":"https://api.github.com/repos/opencv/opencv/issues/13494","repository_url":"https://api.github.com/repos/opencv/opencv","labels_url":"https://api.github.com/repos/opencv/opencv/issues/13494/labels{/name}","comments_url":"https://api.github.com/repos/opencv/opencv/issues/13494/comments","events_url":"https://api.github.com/repos/opencv/opencv/issues/13494/events","html_url":"https://github.com/opencv/opencv/issues/13494","id":393318769,"node_id":"MDU6SXNzdWUzOTMzMTg3Njk=","number":13494,"title":"Fail to do network forward after loading a sub-pixel layer","user":{"login":"JVision","id":2658584,"node_id":"MDQ6VXNlcjI2NTg1ODQ=","avatar_url":"https://avatars1.githubusercontent.com/u/2658584?v=4","gravatar_id":"","url":"https://api.github.com/users/JVision","html_url":"https://github.com/JVision","followers_url":"https://api.github.com/users/JVision/followers","following_url":"https://api.github.com/users/JVision/following{/other_user}","gists_url":"https://api.github.com/users/JVision/gists{/gist_id}","starred_url":"https://api.github.com/users/JVision/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JVision/subscriptions","organizations_url":"https://api.github.com/users/JVision/orgs","repos_url":"https://api.github.com/users/JVision/repos","events_url":"https://api.github.com/users/JVision/events{/privacy}","received_events_url":"https://api.github.com/users/JVision/received_events","type":"User","site_admin":false},"labels":[{"id":635087908,"node_id":"MDU6TGFiZWw2MzUwODc5MDg=","url":"https://api.github.com/repos/opencv/opencv/labels/category:%20dnn","name":"category: dnn","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-12-21T05:16:11Z","updated_at":"2018-12-21T06:15:42Z","closed_at":null,"author_association":"NONE","body":"##### System information (version)\r\n- OpenCV => 3.4.4\r\n- Operating System / Platform => Windows 64 Bit\r\n- Compiler => Visual Studio 2015\r\n\r\n##### Detailed description\r\nI've implemented a simple subpixel layer using tensorlayers. However, could not get correct results using opencv dnn. \r\n\r\nThe code is given as below:\r\n\r\n```python\r\ndef test_subpixel():\r\n    import cv2 as cv\r\n    import numpy as np\r\n    import tensorflow as tf\r\n\r\n    graph = './_Cache/simple_subpixel.optimized.pb'\r\n    \r\n    inp = np.linspace(1,4, 4).reshape(1, 4, 1, 1)\r\n    output_node_name = 'SUBPIXEL/SUBPIXEL/subpixel_image/Identity'\r\n\r\n    # Run TensorFlow\r\n    with tf.gfile.FastGFile(graph, 'rb') as f:\r\n        graph_def = tf.GraphDef()\r\n        graph_def.ParseFromString(f.read())\r\n\r\n    with tf.Session() as sess:\r\n        # Restore session\r\n        sess.graph.as_default()\r\n        tf.import_graph_def(graph_def, name='')\r\n        tfOut = sess.run(sess.graph.get_tensor_by_name(output_node_name+\":0\"),\r\n                        feed_dict={'input_image:0': inp.transpose(0, 2, 3, 1)}) \r\n        tfOut_flat = tfOut.transpose(0, 3, 1, 2)[0, 0, :,:]\r\n    # Run OpenCV\r\n    net = cv.dnn.readNet(graph)\r\n    net.setInput(inp)\r\n    cvOut = net.forward(output_node_name)\r\n    d1 = cvOut[0,0,:,:]\r\n    d2 = tfOut_flat\r\n    max_error = np.max(np.abs(d1 - d2))\r\n    print(max_error)\r\n```\r\n\r\nAn error pops up when running the above piece of code:\r\n\r\n`OpenCV(3.4.4-dev) Error: Unspecified error (Can't create layer \"SUBPIXEL/SUBPIXEL/subpixel_image/Shape\" of type \"Shape\") in cv::dnn::experimental_dnn_34_v10::LayerData::getLayerInstance, file E:\\opencv\\modules\\dnn\\src\\dnn.cpp, line 513\r\n`\r\n\r\n<!-- your description -->\r\n\r\n##### Steps to reproduce\r\nto reproduce the issue, please download and unzip the attached file and put the .pb file into the same folder as the test code and run. \r\n\r\n[pbs.zip](https://github.com/opencv/opencv/files/2701592/pbs.zip)\r\n\r\n\r\n1. load the pb files as attached. \r\n2. running the code snippets as given. \r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/opencv/opencv/issues/comments/449270164","html_url":"https://github.com/opencv/opencv/issues/13494#issuecomment-449270164","issue_url":"https://api.github.com/repos/opencv/opencv/issues/13494","id":449270164,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0OTI3MDE2NA==","user":{"login":"JVision","id":2658584,"node_id":"MDQ6VXNlcjI2NTg1ODQ=","avatar_url":"https://avatars1.githubusercontent.com/u/2658584?v=4","gravatar_id":"","url":"https://api.github.com/users/JVision","html_url":"https://github.com/JVision","followers_url":"https://api.github.com/users/JVision/followers","following_url":"https://api.github.com/users/JVision/following{/other_user}","gists_url":"https://api.github.com/users/JVision/gists{/gist_id}","starred_url":"https://api.github.com/users/JVision/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JVision/subscriptions","organizations_url":"https://api.github.com/users/JVision/orgs","repos_url":"https://api.github.com/users/JVision/repos","events_url":"https://api.github.com/users/JVision/events{/privacy}","received_events_url":"https://api.github.com/users/JVision/received_events","type":"User","site_admin":false},"created_at":"2018-12-21T06:15:42Z","updated_at":"2018-12-21T06:15:42Z","author_association":"NONE","body":"@dkurt Yes it is. here's the code snippet to generate the graph.\r\n\r\n`import os\r\nimport tensorflow as tf\r\nimport tensorlayer as tl\r\nimport numpy\r\n\r\ndef tf_test_subpixel(reuse = False):\r\n    in_channels = 4\r\n    out_channels = 1\r\n    scale = 2\r\n    w = 1\r\n    h = 1\r\n    inputs = tf.placeholder(tf.float32, shape=[None, w, h, in_channels], name=\"input_image\")\r\n    \r\n    with tf.variable_scope(\"SUBPIXEL\", reuse=reuse) as vs:\r\n        tl.layers.set_name_reuse(reuse)\r\n        inputs_level = InputLayer(inputs, name='input_level')\r\n        net_image = SubpixelConv2d(inputs_level,scale=2 ,n_out_channel=1,  name='subpixel_image')\r\n\r\n    output = net_image\r\n\r\n    sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=False))\r\n    tl.layers.initialize_global_variables(sess)\r\n\r\n    \r\n    test_input = numpy.random.randn(1, w, h, in_channels)\r\n    sample_out = sess.run([output.outputs], {inputs:test_input})\r\n`"}}
{"actor":{"display_login":"JVision"}}