public final class Tensor
extends java.lang.Object
The native handle of a Tensor is managed by NativeInterpreterWrapper, and does
not needed to be closed by the client. However, once the NativeInterpreterWrapper has
been closed, the tensor handle will be invalidated.
| Modifier and Type | Class and Description |
|---|---|
static class |
Tensor.QuantizationParams
Quantization parameters that corresponds to the table,
QuantizationParameters, in the
TFLite
Model schema file. |
| Modifier and Type | Method and Description |
|---|---|
java.nio.ByteBuffer |
buffer() |
void |
close()
Disposes of any resources used by the Tensor wrapper.
|
void |
copyTo(java.nio.Buffer dst) |
java.lang.Object |
copyTo(java.lang.Object dst)
Copies the contents of the tensor to
dst and returns dst. |
DataType |
dataType()
Returns the
DataType of elements stored in the Tensor. |
int |
index()
Returns the (global) index of the tensor within the owning
Interpreter. |
java.lang.String |
name()
Returns the name of the tensor within the owning
Interpreter. |
int |
numBytes()
Returns the size, in bytes, of the tensor data.
|
int |
numDimensions()
Returns the number of dimensions (sometimes referred to as rank) of the Tensor.
|
int |
numElements()
Returns the number of elements in a flattened (1-D) view of the tensor.
|
Tensor.QuantizationParams |
quantizationParams()
Returns the quantization parameters of the tensor within the owning
Interpreter. |
void |
setTo(java.nio.Buffer src) |
void |
setTo(java.lang.Object src)
Copies the contents of the provided
src object to the Tensor. |
int[] |
shape()
Returns the shape of
the Tensor, i.e., the sizes of each dimension.
|
int[] |
shapeSignature()
Returns the original shape of the Tensor,
i.e., the sizes of each dimension - before any resizing was performed.
|
public void close()
public int numDimensions()
Will be 0 for a scalar, 1 for a vector, 2 for a matrix, 3 for a 3-dimensional tensor etc.
public int numBytes()
public int numElements()
public int[] shape()
public int[] shapeSignature()
public int index()
Interpreter.public java.lang.String name()
Interpreter.public Tensor.QuantizationParams quantizationParams()
Interpreter.
Only quantized tensors have valid QuantizationParameters. For tensor that are not
quantized, the values of scale and zero_point are both 0.
public void setTo(java.lang.Object src)
src object to the Tensor.
The src should either be a (multi-dimensional) array with a shape matching that of
this tensor, a ByteBuffer of compatible primitive type with a matching flat size, or
null iff the tensor has an underlying delegate buffer handle.
java.lang.IllegalArgumentException - if the tensor is a scalar or if src is not
compatible with the tensor (for example, mismatched data types or shapes).public void setTo(java.nio.Buffer src)
public java.lang.Object copyTo(java.lang.Object dst)
dst and returns dst.dst - the destination buffer, either an explicitly-typed array, a ByteBuffer or
null iff the tensor has an underlying delegate buffer handle.java.lang.IllegalArgumentException - if dst is not compatible with the tensor (for
example, mismatched data types or shapes).public void copyTo(java.nio.Buffer dst)
public java.nio.ByteBuffer buffer()