Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
fluxo tensor:: ops:: OneHot
#include <array_ops.h>
Retorna um tensor one-hot.
Resumo
Os locais representados pelos índices nos indices
assumem o valor on_value
, enquanto todos os outros locais assumem o valor off_value
.
Se os indices
de entrada forem de classificação N
, a saída terá classificação N+1
. O novo eixo é criado no axis
de dimensão (padrão: o novo eixo é anexado no final).
Se indices
forem escalares, a forma de saída será um vetor de comprimento depth
.
Se indices
for um vetor de features
de comprimento, a forma de saída será:
features x depth if axis == -1
depth x features if axis == 0
Se indices
forem uma matriz (lote) com formato [batch, features]
, o formato de saída será:
batch x features x depth if axis == -1
batch x depth x features if axis == 1
depth x batch x features if axis == 0
Exemplos
Suponha que
indices = [0, 2, -1, 1]
depth = 3
on_value = 5.0
off_value = 0.0
axis = -1
Então a saída é [4 x 3]
:
output =
[5.0 0.0 0.0] // one_hot(0)
[0.0 0.0 5.0] // one_hot(2)
[0.0 0.0 0.0] // one_hot(-1)
[0.0 5.0 0.0] // one_hot(1)
Suponha que
indices = [0, 2, -1, 1]
depth = 3
on_value = 0.0
off_value = 3.0
axis = 0
Então a saída é [3 x 4]
:
output =
[0.0 3.0 3.0 3.0]
[3.0 3.0 3.0 0.0]
[3.0 3.0 3.0 3.0]
[3.0 0.0 3.0 3.0]
// ^ one_hot(0)
// ^ one_hot(2)
// ^ one_hot(-1)
// ^ one_hot(1)
Suponha que
indices = [[0, 2], [1, -1]]
depth = 3
on_value = 1.0
off_value = 0.0
axis = -1
Então a saída é [2 x 2 x 3]
:
output =
[
[1.0, 0.0, 0.0] // one_hot(0)
[0.0, 0.0, 1.0] // one_hot(2)
][
[0.0, 1.0, 0.0] // one_hot(1)
[0.0, 0.0, 0.0] // one_hot(-1)
]
Argumentos:
- escopo: um objeto Escopo
- índices: Um tensor de índices.
- profundidade: Um escalar que define a profundidade de uma dimensão quente.
- on_value: um escalar que define o valor a ser preenchido na saída quando
indices[j] = i
. - off_value: um escalar que define o valor a ser preenchido na saída quando
indices[j] != i
.
Atributos opcionais (veja Attrs
):
- eixo: O eixo a ser preenchido (padrão: -1, um novo eixo mais interno).
Retorna:
Funções estáticas públicas |
---|
Axis (int64 x) | |
Atributos públicos
Funções públicas
nó
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operador::tensorflow::Saída
operator::tensorflow::Output() const
Funções estáticas públicas
Eixo
Attrs Axis(
int64 x
)
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
Última atualização 2025-07-27 UTC.
[null,null,["Última atualização 2025-07-27 UTC."],[],[],null,["# tensorflow::ops::OneHot Class Reference\n\ntensorflow::ops::OneHot\n=======================\n\n`#include \u003carray_ops.h\u003e`\n\nReturns a one-hot tensor.\n\nSummary\n-------\n\nThe locations represented by indices in `indices` take value `on_value`, while all other locations take value `off_value`.\n\nIf the input `indices` is rank `N`, the output will have rank `N+1`, The new axis is created at dimension `axis` (default: the new axis is appended at the end).\n\nIf `indices` is a scalar the output shape will be a vector of length `depth`.\n\nIf `indices` is a vector of length `features`, the output shape will be: \n\n```text\n features x depth if axis == -1\n depth x features if axis == 0\n```\n\n\u003cbr /\u003e\n\nIf `indices` is a matrix (batch) with shape `[batch, features]`, the output shape will be: \n\n```text\n batch x features x depth if axis == -1\n batch x depth x features if axis == 1\n depth x batch x features if axis == 0\n```\n\n\u003cbr /\u003e\n\n\nExamples\n========\n\n\u003cbr /\u003e\n\nSuppose that \n\n```scdoc\n indices = [0, 2, -1, 1]\n depth = 3\n on_value = 5.0\n off_value = 0.0\n axis = -1\n```\n\n\u003cbr /\u003e\n\nThen output is `[4 x 3]`: \n\n```scdoc\noutput =\n [5.0 0.0 0.0] // one_hot(0)\n [0.0 0.0 5.0] // one_hot(2)\n [0.0 0.0 0.0] // one_hot(-1)\n [0.0 5.0 0.0] // one_hot(1)\n```\n\n\u003cbr /\u003e\n\nSuppose that \n\n```scdoc\n indices = [0, 2, -1, 1]\n depth = 3\n on_value = 0.0\n off_value = 3.0\n axis = 0\n```\n\n\u003cbr /\u003e\n\nThen output is `[3 x 4]`: \n\n```scdoc\noutput =\n [0.0 3.0 3.0 3.0]\n [3.0 3.0 3.0 0.0]\n [3.0 3.0 3.0 3.0]\n [3.0 0.0 3.0 3.0]\n// ^ one_hot(0)\n// ^ one_hot(2)\n// ^ one_hot(-1)\n// ^ one_hot(1)\n```\n\n\u003cbr /\u003e\n\nSuppose that \n\n```scdoc\n indices = [[0, 2], [1, -1]]\n depth = 3\n on_value = 1.0\n off_value = 0.0\n axis = -1\n```\n\n\u003cbr /\u003e\n\nThen output is `[2 x 2 x 3]`: \n\n```scdoc\noutput =\n [\n [1.0, 0.0, 0.0] // one_hot(0)\n [0.0, 0.0, 1.0] // one_hot(2)\n ][\n [0.0, 1.0, 0.0] // one_hot(1)\n [0.0, 0.0, 0.0] // one_hot(-1)\n ]\n```\n\n\u003cbr /\u003e\n\nArguments:\n\n- scope: A [Scope](/versions/r2.2/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- indices: A tensor of indices.\n- depth: A scalar defining the depth of the one hot dimension.\n- on_value: A scalar defining the value to fill in output when `indices[j] = i`.\n- off_value: A scalar defining the value to fill in output when `indices[j] != i`.\n\n\u003cbr /\u003e\n\nOptional attributes (see [Attrs](/versions/r2.2/api_docs/cc/struct/tensorflow/ops/one-hot/attrs#structtensorflow_1_1ops_1_1_one_hot_1_1_attrs)):\n\n- axis: The axis to fill (default: -1, a new inner-most axis).\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.2/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): The one-hot tensor.\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [OneHot](#classtensorflow_1_1ops_1_1_one_hot_1a854f72c62e64f05c6b259c56ea5734bf)`(const ::`[tensorflow::Scope](/versions/r2.2/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` indices, ::`[tensorflow::Input](/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` depth, ::`[tensorflow::Input](/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` on_value, ::`[tensorflow::Input](/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` off_value)` ||\n| [OneHot](#classtensorflow_1_1ops_1_1_one_hot_1a606bee0fc38c4a1041cb1cd0be5920ca)`(const ::`[tensorflow::Scope](/versions/r2.2/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` indices, ::`[tensorflow::Input](/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` depth, ::`[tensorflow::Input](/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` on_value, ::`[tensorflow::Input](/versions/r2.2/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` off_value, const `[OneHot::Attrs](/versions/r2.2/api_docs/cc/struct/tensorflow/ops/one-hot/attrs#structtensorflow_1_1ops_1_1_one_hot_1_1_attrs)` & attrs)` ||\n\n| ### Public attributes ||\n|-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| [operation](#classtensorflow_1_1ops_1_1_one_hot_1aa5fc51f1f352f7ce7ffb0906b98ab4ec) | [Operation](/versions/r2.2/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_one_hot_1a120b99aec6bb831f0cec75b08bb8ab99) | `::`[tensorflow::Output](/versions/r2.2/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n\n| ### Public functions ||\n|-------------------------------------------------------------------------------------------------------------------|------------------------|\n| [node](#classtensorflow_1_1ops_1_1_one_hot_1a79ee3b14e2833cd20e87ac9ed19c8852)`() const ` | `::tensorflow::Node *` |\n| [operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_one_hot_1afd6cf127f64b799170e3bbdb63bbf3a8)`() const ` | ` ` ` ` |\n| [operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_one_hot_1aeb4ae438117dbe3d0e9a0ff8af670b54)`() const ` | ` ` ` ` |\n\n| ### Public static functions ||\n|-------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|\n| [Axis](#classtensorflow_1_1ops_1_1_one_hot_1a11c56717df9255c7d78ae73a2a9349f6)`(int64 x)` | [Attrs](/versions/r2.2/api_docs/cc/struct/tensorflow/ops/one-hot/attrs#structtensorflow_1_1ops_1_1_one_hot_1_1_attrs) |\n\n| ### Structs ||\n|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|\n| [tensorflow::ops::OneHot::Attrs](/versions/r2.2/api_docs/cc/struct/tensorflow/ops/one-hot/attrs) | Optional attribute setters for [OneHot](/versions/r2.2/api_docs/cc/class/tensorflow/ops/one-hot#classtensorflow_1_1ops_1_1_one_hot). |\n\nPublic attributes\n-----------------\n\n### operation\n\n```text\nOperation operation\n``` \n\n### output\n\n```text\n::tensorflow::Output output\n``` \n\nPublic functions\n----------------\n\n### OneHot\n\n```gdscript\n OneHot(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input indices,\n ::tensorflow::Input depth,\n ::tensorflow::Input on_value,\n ::tensorflow::Input off_value\n)\n``` \n\n### OneHot\n\n```gdscript\n OneHot(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input indices,\n ::tensorflow::Input depth,\n ::tensorflow::Input on_value,\n ::tensorflow::Input off_value,\n const OneHot::Attrs & attrs\n)\n``` \n\n### node\n\n```gdscript\n::tensorflow::Node * node() const \n``` \n\n### operator::tensorflow::Input\n\n```gdscript\n operator::tensorflow::Input() const \n``` \n\n### operator::tensorflow::Output\n\n```gdscript\n operator::tensorflow::Output() const \n``` \n\nPublic static functions\n-----------------------\n\n### Axis\n\n```text\nAttrs Axis(\n int64 x\n)\n```"]]