Tf.Print() doesn't print the shape of the tensors?

不羁的心 提交于 2019-12-05 11:48:00

That is not how you use tf.Print. It is an op that does nothing on its own (simply returns the input) but prints the requested tensors as a side effect. You should do something like

logits = tf.Print(logits, [tf.shape(features),
                           tf.shape(labels),
                           tf.shape(w),
                           tf.shape(b),
                           tf.shape(logits)],
                  message= "The shapes are:")

Now, whenever logits is evaluated (as it will be for computing the loss/gradients), the shape information will be printed.

What you are doing right now is simply printing the return value of the tf.Print op, which is just its input (tf.shape(features)).

After @xdurch0 suggestion, I tried this

shapes = tf.Print(logits, [tf.shape(features),
                       tf.shape(labels),
                       tf.shape(w),
                       tf.shape(b),
                       tf.shape(logits)],
              message= "The shapes are:")
# Run optimizer and get loss
_, l, resultingShapes = session.run( [optimizer, loss, shapes],
                                     feed_dict={features: train_features, labels: train_labels})
print('The shapes are: '. resultingShapes.shape)

and it worked partially,

Extracting dataset/mnist/train-images-idx3-ubyte.gz
Extracting dataset/mnist/train-labels-idx1-ubyte.gz
Extracting dataset/mnist/t10k-images-idx3-ubyte.gz
Extracting dataset/mnist/t10k-labels-idx1-ubyte.gz
Total 3118 data points of Training Data, each having 784 features 
       Total 3118 number of labels, each having 1-hot encoding [0. 1. 0.]
The shapes are:  (3118, 3)

Loss: 10.223002433776855

could @xdurch0 suggest something to get the desired results?

My DESIRED RESULTS are:

tf.shape(features): (3118, 784) tf.shape(labels) :(3118, 3) ,

tf.shape(w) : (784,3), tf.shape(b) : (3,1), tf.shape(logits):(3118,3)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!