Comments (5)
Just jumping into this ticket as well, so the proper way to create tensors now is by using factories exposed by the type themselves. Here's a few examples for 32-bit integer tensors:
Tensor<TInt32> scalar = TInt32.scalarOf(0);
Tensor<TInt32> array = TInt32.vectorOf(1, 2, 3, 4);
// this is efficient for large tensors, as it does not require to preallocate or
// duplicate the whole data before feeding the tensor
Tensor<TInt32> matrix = TInt32.tensorOf(Shape.of(2, 4), data ->
// your input loop here, you could read from an `InputStream`, etc. but let's use
// a simple case as an example
data.set(NdArrays.vectorOf(1, 2, 3, 4), 0)
.set(NdArrays.vectorOf(5, 6, 7, 8), 1)
);
// this can be more convenient for small tensors, for the improved syntax
Tensor<TInt32> matrix3d = TInt32.tensorOf(StdArrays.ndCopyOf(new int[][][] {
{
{1, 2, 3}, {4, 5, 6}
},
{
{7, 8, 9}, {10, 11, 12}
}
}));
// and more options...
You can do pretty much the same using the Constant
for tensors with a fix value in a graph.
And finally, you can rely on the Tensor
factories if you need better fine-tuning or selection of the datatype at runtime.
from java.
It depends what you are trying to do, but the Tensor infrastructure now creates tensors from NdArrays which are defined in tensorflow-tools. To use the old slow path you can create an NdArray using org.tensorflow.tools.ndarray.StdArrays
, and then feed the resulting object into <Type>.tensorOf()
, where is the type of Tensor
you want to create (e.g. TFloat32
, TInt32
etc). If your data isn't stored in a java multidimensional array then we recommend that you write it directly into an NdArray
after allocating one of the appropriate size (using org.tensorflow.types.<type>.tensorOf(shape)
.
from java.
Thanks for reply!!
Can you please share what is alternative way?
from java.
Those methods are horribly inefficient due to the way Java multidimensional arrays are constructed, so they've been removed from the new API.
from java.
I'm too looking for some better alternative, any help would be great.
from java.
Related Issues (20)
- ivy dependency not working on windows or linux, native TF code not found on classpath HOT 5
- Could not load dynamic library 'xxxxx'; dlerror: xxxxx.dll not found HOT 5
- org.tensorflow.TensorFlowException: Can't parse /<modelPath>/<somePathToFolder>/saved_model.pb as binary proto - JDK 17 HOT 15
- Compiling from source, cuDNN version is not compatible? How can I change the cuDNN compile version? HOT 2
- SavedModelBundle Unable to Load Models with coo_sparse Encoded Input HOT 1
- Tensor type issue HOT 3
- Unable to build the project using 'mvn install ' command HOT 4
- how to use importGraphDef to load model.pb file? HOT 2
- Modular Java app can't create tensor object HOT 3
- Read/Write method of DataBuffer is against intuition HOT 1
- Distributing an Apple Silicon binary HOT 2
- Error when using tensorflow-text on tensorflow-core HOT 8
- Reductions on losses that have dynamic size
- No documentation for 1.0.0 HOT 5
- The loss CatagoricalCrossEntropy is currently unusable in framework
- Build native codes current master fails HOT 4
- Native artifacts are pulling transitive dependencies
- Q: How to add Regularizer and Constraint effect correctly to a weight/bias variable or activity? HOT 1
- Which is the "org.tensorflow.Tensor#create(java.lang.Object)" substitute? HOT 2
- right dependency for org.tensorflow.proto.framework? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java.