Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
tensoreflusso:: ops:: OneHot
#include <array_ops.h>
Restituisce un tensore one-hot.
Riepilogo
Le posizioni rappresentate dagli indici negli indices
assumono valore on_value
, mentre tutte le altre posizioni assumono valore off_value
.
Se gli indices
di input sono di rango N
, l'output avrà rango N+1
. Il nuovo asse viene creato axis
dimensione (impostazione predefinita: il nuovo asse viene aggiunto alla fine).
Se indices
è uno scalare, la forma di output sarà un vettore di lunghezza depth
.
Se indices
è un vettore di features
di lunghezza, la forma di output sarà:
features x depth if axis == -1
depth x features if axis == 0
Se indices
è una matrice (batch) con forma [batch, features]
, la forma di output sarà:
batch x features x depth if axis == -1
batch x depth x features if axis == 1
depth x batch x features if axis == 0
Esempi
Supponiamolo
indices = [0, 2, -1, 1]
depth = 3
on_value = 5.0
off_value = 0.0
axis = -1
Quindi l'output è [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)
Supponiamolo
indices = [0, 2, -1, 1]
depth = 3
on_value = 0.0
off_value = 3.0
axis = 0
Quindi l'output è [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)
Supponiamolo
indices = [[0, 2], [1, -1]]
depth = 3
on_value = 1.0
off_value = 0.0
axis = -1
Quindi l'output è [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)
]
Argomenti:
- scope: un oggetto Scope
- indici: un tensore di indici.
- profondità: uno scalare che definisce la profondità di una dimensione calda.
- on_value: uno scalare che definisce il valore da compilare nell'output quando
indices[j] = i
. - off_value: uno scalare che definisce il valore da compilare nell'output quando
indices[j] != i
.
Attributi facoltativi (vedi Attrs
):
- asse: l'asse da riempire (impostazione predefinita: -1, un nuovo asse più interno).
Resi:
-
Output
: il tensore uni-caldo.
Funzioni pubbliche statiche |
---|
Axis (int64 x) | |
Attributi pubblici
Funzioni pubbliche
nodo
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operatore::tensorflow::Output
operator::tensorflow::Output() const
Funzioni pubbliche statiche
Asse
Attrs Axis(
int64 x
)
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-26 UTC.
[null,null,["Ultimo aggiornamento 2025-07-26 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.1/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.1/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.1/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.1/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` indices, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` depth, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` on_value, ::`[tensorflow::Input](/versions/r2.1/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.1/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` indices, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` depth, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` on_value, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` off_value, const `[OneHot::Attrs](/versions/r2.1/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.1/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [output](#classtensorflow_1_1ops_1_1_one_hot_1a120b99aec6bb831f0cec75b08bb8ab99) | `::`[tensorflow::Output](/versions/r2.1/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.1/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.1/api_docs/cc/struct/tensorflow/ops/one-hot/attrs) | Optional attribute setters for [OneHot](/versions/r2.1/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```"]]