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

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.