Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Mhuang77 opened this issue Apr 25, 2024 · 2 comments
Open

Comments

@Mhuang77
Copy link

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?

@Craigacp
Copy link
Collaborator

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

@karllessard
Copy link
Collaborator

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)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants