Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print full value of tensor into console or write to file in tensorflow

I need to print a large tensor ([32,32,3]) into the console, and I only get output like this:

[[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]

[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]

[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]

..., 
[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]

[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]

[[245 245 245]
[245 245 245]
[245 245 245]
..., 
[245 245 245]
[245 245 245]
[245 245 245]]]

How can I get tensorflow to print out the entire tensor, instead of truncating it with the ellipses?

like image 943
Errorsum Avatar asked Feb 09 '16 17:02

Errorsum


People also ask

How do you print the value of a tensor object?

[A]: To print the value of a tensor without returning it to your Python program, you can use the tf. print() operator, as Andrzej suggests in another answer.


2 Answers

The value returned from a TensorFlow Session.run() call is a NumPy ndarray, so this rendering is controlled by NumPy itself. One simple way to ensure that all elements are printed is to use numpy.set_printoptions():

import numpy
numpy.set_printoptions(threshold=numpy.nan)
like image 180
mrry Avatar answered Sep 28 '22 05:09

mrry


use numpy.savetxt:

x = y = z = np.arange(0.0,5.0,1.0)
np.savetxt('test.out', x, delimiter=',')   # X is an array
np.savetxt('test.out', (x,y,z))   # x,y,z equal sized 1D arrays
np.savetxt('test.out', x, fmt='%1.4e')   # use exponential notation
like image 42
Felipe Lema Avatar answered Sep 28 '22 05:09

Felipe Lema