Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
przepływ tensorowy:: ops:: OneHot
#include <array_ops.h>
Zwraca jeden gorący tensor.
Streszczenie
Lokalizacje reprezentowane przez indeksy w indices
przyjmują wartość on_value
, podczas gdy wszystkie inne lokalizacje przyjmują wartość off_value
.
Jeśli indices
wejściowe mają rangę N
, wyjście będzie miało rangę N+1
. Nowa oś tworzona jest na axis
wymiaru (domyślnie: nowa oś jest dodawana na końcu).
Jeśli indices
są skalarami, kształtem wyjściowym będzie wektor długości depth
.
Jeżeli indices
są wektorami features
długości, to wynik będzie następujący:
features x depth if axis == -1
depth x features if axis == 0
Jeśli indices
jest macierz (partia) o kształcie [batch, features]
, kształt wyjściowy będzie następujący:
batch x features x depth if axis == -1
batch x depth x features if axis == 1
depth x batch x features if axis == 0
Przykłady
Załóżmy, że
indices = [0, 2, -1, 1]
depth = 3
on_value = 5.0
off_value = 0.0
axis = -1
Następnie wynik wynosi [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)
Załóżmy, że
indices = [0, 2, -1, 1]
depth = 3
on_value = 0.0
off_value = 3.0
axis = 0
Następnie wynik wynosi [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)
Załóżmy, że
indices = [[0, 2], [1, -1]]
depth = 3
on_value = 1.0
off_value = 0.0
axis = -1
Następnie wynik wynosi [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)
]
Argumenty:
- zakres: Obiekt Scope
- indeksy: tensor indeksów.
- głębokość: Skalar określający głębokość jednego gorącego wymiaru.
- on_value: Skalar definiujący wartość do wypełnienia, gdy
indices[j] = i
. - off_value: Skalar definiujący wartość wypełnianą na wyjściu, gdy
indices[j] != i
.
Opcjonalne atrybuty (patrz Attrs
):
- oś: Oś do wypełnienia (domyślnie: -1, nowa oś najbardziej wewnętrzna).
Zwroty:
-
Output
: Tensor jednego gorącego.
Publiczne funkcje statyczne |
---|
Axis (int64 x) | |
Atrybuty publiczne
Funkcje publiczne
węzeł
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operator::tensorflow::Wyjście
operator::tensorflow::Output() const
Publiczne funkcje statyczne
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-27 UTC.
[null,null,["Ostatnia aktualizacja: 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```"]]