Uma matriz multidimensional tipada usada no Tensorflow Lite.
O identificador nativo de um Tensor é gerenciado pelo NativeInterpreterWrapper e
que não precisa ser fechado pelo cliente. No entanto, assim que NativeInterpreterWrapper
for fechado, o handle do tensor será invalidado.
Retorna uma visualização ByteBuffer somente leitura dos dados do tensor.
Em geral, esse método é mais útil para obter uma visualização somente leitura dos dados do tensor de saída,
*após* a inferência ter sido executada (por exemplo, via InterpreterApi.run(Object, Object)). Em
Alguns gráficos têm saídas de formato dinâmico, o que pode tornar o feed
um buffer de saída estranho para o intérprete. Exemplo de uso:
interpreter.run(input, null);
ByteBuffer outputBuffer = interpreter.getOutputTensor(0).asReadOnlyBuffer();
// Copy or read from outputBuffer.
AVISO: se o tensor ainda não tiver sido alocado, por exemplo, antes que a inferência seja executada,
o resultado é indefinido. O ponteiro do tensor também pode mudar quando o
Tensor é invalidado de alguma forma (por exemplo, se a inferência for executada ou o grafo for redimensionado).
*não* é seguro manter uma referência ao buffer retornado além do uso imediato
após a inferência. Exemplo de uso *ruim*:
ByteBuffer outputBuffer = interpreter.getOutputTensor(0).asReadOnlyBuffer();
interpreter.run(input, null);
// Copy or read from outputBuffer (which may now be invalid).
Retorna os parâmetros de quantização do tensor no interpretador proprietário.
Somente tensores quantizados têm um QuantizationParameters válido. Para tensores que não são
quantizados, os valores de scale e zero_point serão 0.
públicas
abstrato
int[]
forma()
Retorna a forma do
o tensor, ou seja, os tamanhos de cada dimensão.
Retorna
uma matriz em que o elemento i-ésimo é o tamanho da i-ésima dimensão do tensor.
públicas
abstrato
int[]
shapeSignature()
Retorna o formato original do tensor,
ou seja, os tamanhos de cada dimensão, antes de qualquer redimensionamento. Dimensões desconhecidas são
designado com um valor de -1.
Retorna
uma matriz em que o elemento i-ésimo é o tamanho da i-ésima dimensão do tensor.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Não contém as informações de que eu preciso","missingTheInformationINeed","thumb-down"],["Muito complicado / etapas demais","tooComplicatedTooManySteps","thumb-down"],["Desatualizado","outOfDate","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Problema com as amostras / o código","samplesCodeIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-07-24 UTC."],[],[],null,["# Tensor\n\npublic interface **Tensor** \nA typed multi-dimensional array used in Tensorflow Lite.\n\nThe native handle of a `Tensor` is managed by `NativeInterpreterWrapper`, and does\nnot needed to be closed by the client. However, once the `NativeInterpreterWrapper` has\nbeen closed, the tensor handle will be invalidated.\n\n\u003cbr /\u003e\n\n### Nested Classes\n\n|-------|---|---|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| class | [Tensor.QuantizationParams](/edge/api/tflite/java/org/tensorflow/lite/Tensor.QuantizationParams) || Quantization parameters that corresponds to the table, `QuantizationParameters`, in the [TFLite Model schema file.](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/schema/schema.fbs) |\n\n### Public Methods\n\n|-----------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html) | [asReadOnlyBuffer](/edge/api/tflite/java/org/tensorflow/lite/Tensor#asReadOnlyBuffer())() Returns a read-only `ByteBuffer` view of the tensor data. |\n| abstract [DataType](/edge/api/tflite/java/org/tensorflow/lite/DataType) | [dataType](/edge/api/tflite/java/org/tensorflow/lite/Tensor#dataType())() Returns the [DataType](/edge/api/tflite/java/org/tensorflow/lite/DataType) of elements stored in the Tensor. |\n| abstract int | [numBytes](/edge/api/tflite/java/org/tensorflow/lite/Tensor#numBytes())() Returns the size, in bytes, of the tensor data. |\n| abstract int | [numDimensions](/edge/api/tflite/java/org/tensorflow/lite/Tensor#numDimensions())() Returns the number of dimensions (sometimes referred to as [rank](https://www.tensorflow.org/resources/dims_types.html#rank)) of the Tensor. |\n| abstract int | [numElements](/edge/api/tflite/java/org/tensorflow/lite/Tensor#numElements())() Returns the number of elements in a flattened (1-D) view of the tensor. |\n| abstract [Tensor.QuantizationParams](/edge/api/tflite/java/org/tensorflow/lite/Tensor.QuantizationParams) | [quantizationParams](/edge/api/tflite/java/org/tensorflow/lite/Tensor#quantizationParams())() Returns the quantization parameters of the tensor within the owning interpreter. |\n| abstract int\\[\\] | [shape](/edge/api/tflite/java/org/tensorflow/lite/Tensor#shape())() Returns the [shape](https://www.tensorflow.org/resources/dims_types.html#shape) of the Tensor, i.e., the sizes of each dimension. |\n| abstract int\\[\\] | [shapeSignature](/edge/api/tflite/java/org/tensorflow/lite/Tensor#shapeSignature())() Returns the original [shape](https://www.tensorflow.org/resources/dims_types.html#shape) of the Tensor, i.e., the sizes of each dimension - before any resizing was performed. |\n\nPublic Methods\n--------------\n\n#### public abstract [ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html)\n**asReadOnlyBuffer**\n()\n\nReturns a read-only `ByteBuffer` view of the tensor data.\n\nIn general, this method is most useful for obtaining a read-only view of output tensor data,\n\\*after\\* inference has been executed (e.g., via [InterpreterApi.run(Object, Object)](/edge/api/tflite/java/org/tensorflow/lite/InterpreterApi#run(java.lang.Object,%20java.lang.Object))). In\nparticular, some graphs have dynamically shaped outputs, which can make feeding a predefined\noutput buffer to the interpreter awkward. Example usage:\n\n interpreter.run(input, null);\n ByteBuffer outputBuffer = interpreter.getOutputTensor(0).asReadOnlyBuffer();\n // Copy or read from outputBuffer.\n\nWARNING: If the tensor has not yet been allocated, e.g., before inference has been executed,\nthe result is undefined. Note that the underlying tensor pointer may also change when the\ntensor is invalidated in any way (e.g., if inference is executed, or the graph is resized), so\nit is \\*not\\* safe to hold a reference to the returned buffer beyond immediate use directly\nfollowing inference. Example \\*bad\\* usage:\n\n ByteBuffer outputBuffer = interpreter.getOutputTensor(0).asReadOnlyBuffer();\n interpreter.run(input, null);\n // Copy or read from outputBuffer (which may now be invalid).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n##### Throws\n\n| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if the tensor data has not been allocated. |\n|-------------------------------------------------------------------------------------------------------------|--------------------------------------------|\n\n#### public abstract [DataType](/edge/api/tflite/java/org/tensorflow/lite/DataType)\n**dataType**\n()\n\nReturns the [DataType](/edge/api/tflite/java/org/tensorflow/lite/DataType) of elements stored in the Tensor. \n\n#### public abstract int\n**numBytes**\n()\n\nReturns the size, in bytes, of the tensor data. \n\n#### public abstract int\n**numDimensions**\n()\n\nReturns the number of dimensions (sometimes referred to as [rank](https://www.tensorflow.org/resources/dims_types.html#rank)) of the Tensor.\n\nWill be 0 for a scalar, 1 for a vector, 2 for a matrix, 3 for a 3-dimensional tensor etc.\n\n\u003cbr /\u003e\n\n#### public abstract int\n**numElements**\n()\n\nReturns the number of elements in a flattened (1-D) view of the tensor. \n\n#### public abstract [Tensor.QuantizationParams](/edge/api/tflite/java/org/tensorflow/lite/Tensor.QuantizationParams)\n**quantizationParams**\n()\n\nReturns the quantization parameters of the tensor within the owning interpreter.\n\nOnly quantized tensors have valid `QuantizationParameters`. For tensor that are not\nquantized, the values of scale and zero_point are both 0.\n\n\u003cbr /\u003e\n\n#### public abstract int\\[\\]\n**shape**\n()\n\nReturns the [shape](https://www.tensorflow.org/resources/dims_types.html#shape) of\nthe Tensor, i.e., the sizes of each dimension. \n\n##### Returns\n\n- an array where the i-th element is the size of the i-th dimension of the tensor. \n\n#### public abstract int\\[\\]\n**shapeSignature**\n()\n\nReturns the original [shape](https://www.tensorflow.org/resources/dims_types.html#shape) of the Tensor,\ni.e., the sizes of each dimension - before any resizing was performed. Unknown dimensions are\ndesignated with a value of -1. \n\n##### Returns\n\n- an array where the i-th element is the size of the i-th dimension of the tensor."]]