Added the TensorCreation.java example#7
Conversation
|
Dear @karllessard could you have a look to this small PR? Could it be merged? |
There was a problem hiding this comment.
Hey @zaleslaw , thanks for the PR! I like it overall, we need more of those. Just added a few comments and we are good to merge
tensorflow-examples/src/main/java/org/tensorflow/model/examples/tensors/TensorCreation.java
Show resolved
Hide resolved
| System.out.println("---- Scalar tensor ---------"); | ||
| System.out.println("DataType: " + rank0Tensor.dataType().name()); | ||
| System.out.println("Rank: " + rank0Tensor.data().rank()); | ||
| System.out.println("NumElements: " + rank0Tensor.data().size()); |
There was a problem hiding this comment.
I think a user should access data() only when he's interested in doing some read/write operations to the tensor memory, as it might move the tensor from some remote location or from GPU memory to the local CPU for this purpose.
Therefore, if the user intent is only to display some metadata about the shape of the tensor, the tensor.shape() method is probably better. (rank0Tensor.shape().numDimensions() and rank0Tensor.shape().size() respectively in this case).
There was a problem hiding this comment.
Agree, but better to have rank() method in tensor interface for next different logic handling for tensors with the different rank
Agree, that maybe I should call methods on data() only for read/write purposes
tensorflow-examples/src/main/java/org/tensorflow/model/examples/tensors/TensorCreation.java
Show resolved
Hide resolved
|
@karllessard I'll fix and return. |
|
@karllessard fixed the review, please have a look |
There was a problem hiding this comment.
All right, I will probably add a bunch of more examples on how to create tensors because there is many other ways to do it
No description provided.