I am trying to get the value of tensor.
# First Layer
encoder_layer1 = tflearn.fully_connected(x,41,activation='relu',bias=True)
layer1_weights = encoder_layer1.W
layer1_bias = encoder_layer1.b
result of printing it out is:
The layer 1 weights are: <tf.Variable 'FullyConnected/W:0' shape=(41, 41) dtype=float32_ref>
even eval() doesn't seem to work. it throws an error
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value FullyConnected/W
[[Node: _send_FullyConnected/W_0 = _Send[T=DT_FLOAT, client_terminated=true, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=-6055748491062458677, tensor_name="FullyConnected/W:0", _device="/job:localhost/replica:0/task:0/cpu:0"](FullyConnected/W)]]
I have tried all the methods metiond but it doesn't seem to work.
Thanks in advance
Shortly:
You can't evaluate any tensor variable outside of session, you must do it inside a session
,
Why can't:
In order to understand why we can't do this, at first we should now what's going on the behind of tensorflow, since every thing in tensorflow is a node of graph, when we define variables and assign values to them, actually we are designing the graph and values are not assigned until we run the graph.
How to run graph:
Session executes the graph, consider the code blocks when we design a network in tensorflow, everything before session like blueprint and after this tf.session as sess
line, like construction site, so you can only evaluate (eval()
) tensors inside session. In the other words, graph defines operations, and operations only execute inside a session.
Hope this was useful. For more, read this