{"action":"created","issue":{"url":"https://api.github.com/repos/tflearn/tflearn/issues/194","repository_url":"https://api.github.com/repos/tflearn/tflearn","labels_url":"https://api.github.com/repos/tflearn/tflearn/issues/194/labels{/name}","comments_url":"https://api.github.com/repos/tflearn/tflearn/issues/194/comments","events_url":"https://api.github.com/repos/tflearn/tflearn/issues/194/events","html_url":"https://github.com/tflearn/tflearn/issues/194","id":164733432,"number":194,"title":"Getting the values of hidden layer nodes","user":{"login":"krayush07","id":9397134,"avatar_url":"https://avatars.githubusercontent.com/u/9397134?v=3","gravatar_id":"","url":"https://api.github.com/users/krayush07","html_url":"https://github.com/krayush07","followers_url":"https://api.github.com/users/krayush07/followers","following_url":"https://api.github.com/users/krayush07/following{/other_user}","gists_url":"https://api.github.com/users/krayush07/gists{/gist_id}","starred_url":"https://api.github.com/users/krayush07/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krayush07/subscriptions","organizations_url":"https://api.github.com/users/krayush07/orgs","repos_url":"https://api.github.com/users/krayush07/repos","events_url":"https://api.github.com/users/krayush07/events{/privacy}","received_events_url":"https://api.github.com/users/krayush07/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-07-10T20:45:42Z","updated_at":"2016-07-12T17:15:59Z","closed_at":null,"body":"Here's a code for XOR in tflearn. I wish to get the values of penultimate hidden layers nodes (and not the weights). I am able to get the weights and biases but unable to compute/get the values of hidden layer nodes, how can I get that? More specifically, I wish to obtain the values of layer2 (given in the code) nodes for each of the four predictions as given below.\r\n\r\n\r\n```python\r\nimport tensorflow as tf\r\nimport tflearn\r\n\r\nX = [[0., 0.], [0., 1.], [1., 0.], [1., 1.]]\r\nY_xor = [[0.], [1.], [1.], [0.]]\r\n\r\n# Graph definition\r\nwith tf.Graph().as_default():\r\n    tnorm = tflearn.initializations.uniform(minval=-1.0, maxval=1.0)\r\n    net = tflearn.input_data(shape=[None, 2], name='inputLayer')\r\n    net = tflearn.fully_connected(net, 2, activation='sigmoid', weights_init=tnorm, name='layer1')\r\n    net = tflearn.fully_connected(net, 1, activation='softmax', weights_init=tnorm, name='layer2')\r\n    regressor = tflearn.regression(net, optimizer='sgd', learning_rate=2., loss='mean_square', name='layer3')\r\n\r\n    # Training\r\n    m = tflearn.DNN(regressor)\r\n    m.fit(X, Y_xor, n_epoch=100, snapshot_epoch=False) \r\n\r\n    # Testing\r\n    print(\"Testing XOR operator\")\r\n    print(\"0 xor 0:\", m.predict([[0., 0.]]))\r\n    print(\"0 xor 1:\", m.predict([[0., 1.]]))\r\n    print(\"1 xor 0:\", m.predict([[1., 0.]]))\r\n    print(\"1 xor 1:\", m.predict([[1., 1.]]))\r\n    \r\n    layer1_var = tflearn.variables.get_layer_variables_by_name('layer1')\r\n    layer2_var = tflearn.variables.get_layer_variables_by_name('layer2')\r\n    inputLayer_var = tflearn.variables.get_layer_variables_by_name('inputLayer')\r\n    \r\n    #result = tf.matmul(inputLayer_var, layer1_var[0]) + layer1_var[1]\r\n    \r\n    with m.session.as_default():\r\n    \tprint(tflearn.variables.get_value(layer1_var[0]))\r\n    \tprint(tflearn.variables.get_value(layer1_var[1]))\r\n    \tprint(tflearn.variables.get_value(layer2_var[0]))\r\n    \tprint(tflearn.variables.get_value(layer2_var[1]))\r\n```"},"comment":{"url":"https://api.github.com/repos/tflearn/tflearn/issues/comments/232114574","html_url":"https://github.com/tflearn/tflearn/issues/194#issuecomment-232114574","issue_url":"https://api.github.com/repos/tflearn/tflearn/issues/194","id":232114574,"user":{"login":"aymericdamien","id":10386605,"avatar_url":"https://avatars.githubusercontent.com/u/10386605?v=3","gravatar_id":"","url":"https://api.github.com/users/aymericdamien","html_url":"https://github.com/aymericdamien","followers_url":"https://api.github.com/users/aymericdamien/followers","following_url":"https://api.github.com/users/aymericdamien/following{/other_user}","gists_url":"https://api.github.com/users/aymericdamien/gists{/gist_id}","starred_url":"https://api.github.com/users/aymericdamien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aymericdamien/subscriptions","organizations_url":"https://api.github.com/users/aymericdamien/orgs","repos_url":"https://api.github.com/users/aymericdamien/repos","events_url":"https://api.github.com/users/aymericdamien/events{/privacy}","received_events_url":"https://api.github.com/users/aymericdamien/received_events","type":"User","site_admin":false},"created_at":"2016-07-12T17:15:59Z","updated_at":"2016-07-12T17:15:59Z","body":"I am not exactly sure about what you want, is it only a way to retrieve the output of multiple layers with a single 'run'? To do this, from my example, you can write:\r\n```python\r\nnet = ...\r\nmerge_op = tflearn.merge([softmax, layer1, layer2], axis=1)\r\nregressor = tflearn.regression(softmax_net, optimizer='adam', learning_rate=0.001, loss='categorical_crossentropy')\r\nm = tflearn.DNN(regressor)\r\n```\r\nAnd then in your output you will have all the selected layers computation."}}
{"actor":{"display_login":"aymericdamien"}}