java icon indicating copy to clipboard operation
java copied to clipboard

Which is the "org.tensorflow.Tensor#create(java.lang.Object)" substitute?

Open Mhuang77 opened this issue 1 year ago • 2 comments
trafficstars

In the TF1.x use the "org.tensorflow.Tensor#create(java.lang.Object)" can conveniently construct various types. Which method in TF2 is equivalent to org.tensorflow.Tensor#create(java.lang.Object) in TF1?

Mhuang77 avatar Apr 25 '24 08:04 Mhuang77

Tensors are created from ndarrays now, you should look at https://github.com/tensorflow/java-ndarray.

Craigacp avatar Apr 25 '24 14:04 Craigacp

In fact, if you are looking at creating TF Tensors, you should use factory methods of classes part of the TType family. For example, to create a integer scalar, you should call TInt32.scalarOf(value) and so on.

TF tensors are ndArrays, but not necessarily the other way around, meaning that if you create tensors only using the java-ndarray library (e.g. NdArrays.scalarOf(integer), you'll get a n-dimensional data structure, yes, but you won't be able to use it directly with TensorFlow and you'll need to convert to a TF Tensor later (e.g. TInt32.tensorOf(ndArray)).

karllessard avatar Apr 26 '24 12:04 karllessard