eaplatanios / tensorflow_scala

TensorFlow API for the Scala Programming Language
http://platanios.org/tensorflow_scala/
Apache License 2.0
937 stars 95 forks source link

Implement nicely formatted numpy style tensor summarize #20

Closed sbrunk closed 6 years ago

sbrunk commented 6 years ago

Formatting of floats and strings could still be polished but I think it's already quite helpful as is.

import org.platanios.tensorflow.api._

scala> val v = tf.Tensor(1.0, 2.34, 0.5)
v: org.platanios.tensorflow.api.tensors.Tensor = FLOAT64[3]

scala> println(v.summarize())
FLOAT64[3]
[1.0, 2.34, 0.5]

scala> val t = tf.Tensor.fill(tf.INT32, tf.shape(3,3))(42)
t: org.platanios.tensorflow.api.tensors.Tensor = INT32[3, 3]
scala> println(t.summarize())
INT32[3, 3]
[[42, 42, 42],
 [42, 42, 42],
 [42, 42, 42]]

scala> val t2 = tf.Tensor.fill(tf.INT32, tf.shape(7,7,7))(42)
t2: org.platanios.tensorflow.api.tensors.Tensor = INT32[7, 7, 7]

scala> println(t2.summarize())
INT32[7, 7, 7]
[[[42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  ...,
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42]],

 [[42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  ...,
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42]],

 [[42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  ...,
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42]],

 ...,

 [[42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  ...,
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42]],

 [[42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  ...,
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42]],

 [[42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  ...,
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42],
  [42, 42, 42, ..., 42, 42, 42]]]
eaplatanios commented 6 years ago

That's great @sbrunk! Thanks a lot! :)