RawTensor

public final class RawTensor

A tensor which memory has not been mapped to a data space directly accessible from the JVM.

A raw tensor is a minimalist representation of a tensor allocated in native memory by the TensorFlow runtime library and it controls its lifetime within the current process. The data is represented by a flat buffer of bytes, until it is mapped in a n-dimensional typed space by a typed tensor.

Instances of a RawTensor are not thread-safe and their resource must be released by calling close() explicitly or implicitly via try-with-resources.

Public Methods

RawTensor
asRawTensor()
Returns a raw (untyped) representation of this tensor
void
close()
Release resources associated with the Tensor.
ByteDataBuffer
data()
Returns the raw data of this tensor as a buffer of bytes.
DataType
dataType()
Returns the DataType of elements stored in the tensor.
long
numBytes()
Returns the size, in bytes, of the tensor data.
Shape
shape()
Returns the shape of the tensor.
String
toString()
Returns a string describing the type and shape of the tensor.

Inherited Methods

boolean
equals(Object arg0)
final Class<?>
getClass()
int
hashCode()
final void
notify()
final void
notifyAll()
String
toString()
final void
wait(long arg0, int arg1)
final void
wait(long arg0)
final void
wait()
org.tensorflow.Tensor
abstract RawTensor
asRawTensor()
Returns a raw (untyped) representation of this tensor
abstract void
close()
Release resources associated with the Tensor.
abstract DataType
dataType()
Returns the DataType of elements stored in the tensor.
abstract long
numBytes()
Returns the size, in bytes, of the tensor data.
abstract static <T extends TType> T
of(Class<T> type, Shape shape, long size, Consumer<T> dataInitializer)
Allocates a tensor of a given datatype, shape and size.
abstract static <T extends TType> T
of(Class<T> type, Shape shape)
Allocates a tensor of a given datatype and shape.
abstract static <T extends TType> T
of(Class<T> type, Shape shape, long size)
Allocates a tensor of a given datatype, shape and size.
abstract static <T extends TType> T
of(Class<T> type, Shape shape, Consumer<T> dataInitializer)
Allocates and initialize a tensor of a given datatype and shape.
abstract static <T extends TType> T
of(Class<T> type, Shape shape, ByteDataBuffer rawData)
Creates a Tensor of any type from the raw data provided by the given buffer.
abstract Shape
shape()
Returns the shape of the tensor.
org.tensorflow.ndarray.Shaped
abstract int
rank()
abstract Shape
shape()
abstract long
size()
Computes and returns the total size of this container, in number of values.
abstract void
close()

Public Methods

public RawTensor asRawTensor ()

Returns a raw (untyped) representation of this tensor

public void close ()

Release resources associated with the Tensor.

WARNING:This must be invoked for all tensors that were not been produced by an eager operation or memory will be leaked.

The Tensor object is no longer usable after close returns.

public ByteDataBuffer data ()

Returns the raw data of this tensor as a buffer of bytes.

Returns
  • the tensor bytes
Throws
IllegalStateException if the tensor has been closed

public DataType dataType ()

Returns the DataType of elements stored in the tensor.

public long numBytes ()

Returns the size, in bytes, of the tensor data.

public Shape shape ()

Returns the shape of the tensor.

public String toString ()

Returns a string describing the type and shape of the tensor.