'Printing a specific dimension of a tensor in tensorflow
I have a tensor x of shape (4,64,5,5). How can I print (or just visualize) the content of a specific dimension?
What I'm trying to do is
with tf.Session() as sess: print(x[0,:,:,:].eval())
but I got the following error:
FailedPreconditionError: Error while reading resource variable dense_2/kernel from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/dense_2/kernel)
I'm using Tensorflow
1.14
Solution 1:[1]
I tried the same in colab in Tensorflow version 1.14 using tf.ones(shape=(4,64,5,5)). It is working fine. Here's the code:
! pip install tensorflow==1.14
import tensorflow as tf
print(tf.__version__)
x=tf.ones(shape=(4,64,5,5))
with tf.Session() as sess: print(x[:,0,0,0].eval())
Output:
1.14.0
[1. 1. 1. 1.]
Let us know if the issue still persists. Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tfer3 |
