java
java copied to clipboard
Which is the "org.tensorflow.Tensor#create(java.lang.Object)" substitute?
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?
Tensors are created from ndarrays now, you should look at https://github.com/tensorflow/java-ndarray.
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)).