コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
テンソルフロー::作戦:: TensorArrayGrad
#include <data_flow_ops.h>
指定されたハンドルに値の勾配を格納するためのTensorArrayを作成します。
まとめ
指定されたTensorArray勾配が既に存在する場合は、その勾配への参照を返します。
動的サイズ フラグを無効にすることで、元のTensorArrayのサイズをロックします。
入力 flow_in に関するメモ:
ハンドル flow_in は、他の特定の操作が発生した後にのみ勾配ルックアップの実行を強制します。たとえば、前方TensorArrayが動的にサイズ変更される場合、このTensorArrayへの書き込みによってオブジェクトのサイズが変更される可能性があります。勾配TensorArray は、この操作の実行時に前方TensorArrayのサイズに基づいて静的にサイズ設定されます。さらに、前方TensorArrayのサイズはこの呼び出しによって固定されます。その結果、このフローは、すべての書き込みが実行された後にのみ、勾配TensorArrayを生成する呼び出しが行われるようにするために使用されます。
動的にサイズ変更される TensorArray の場合、勾配計算は、すべての書き込みが実行された後にのみ発生するようにフローを介してチェーンされている読み取り操作に対してのみ実行する必要があります。そうすることで、このオペレーションが呼び出されたときに、前方TensorArrayの最終サイズがわかります。
ソース属性に関する注意:
TensorArray勾配呼び出しでは、アキュムレータTensorArrayオブジェクトが使用されます。複数の勾配が計算され、同じセッションで実行される場合、複数の勾配ノードが同じアキュムレータTensorArrayを誤って流れる可能性があります。この二重カウントにより、通常はTensorArray の勾配フローが中断されます。
解決策は、この特定のTensorArray勾配が呼び出されている勾配呼び出しを識別することです。これは、入力勾配Tensorの名前から一意の文字列 (例: "gradients"、"gradients_1" など) を識別することによって実行されます。この文字列は、ここでTensorArray勾配オブジェクト (属性source
) を作成するときにサフィックスとして使用されます。
属性source
作成/検索の実行時に前方TensorArrayの名前にサフィックスとして追加されるため、個別の勾配計算はそれぞれ独自のTensorArrayアキュムレータを取得します。
引数:
戻り値:
パブリック属性
公共機能
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-25 UTC。
[null,null,["最終更新日 2025-07-25 UTC。"],[],[],null,["# tensorflow::ops::TensorArrayGrad Class Reference\n\ntensorflow::ops::TensorArrayGrad\n================================\n\n`#include \u003cdata_flow_ops.h\u003e`\n\nCreates a [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) for storing the gradients of values in the given handle.\n\nSummary\n-------\n\nIf the given [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) gradient already exists, returns a reference to it.\n\nLocks the size of the original [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) by disabling its dynamic size flag.\n\n\n**A note about the input flow_in:**\n\nThe handle flow_in forces the execution of the gradient lookup to occur only after certain other operations have occurred. For example, when the forward [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) is dynamically sized, writes to this [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) may resize the object. The gradient [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) is statically sized based on the size of the forward [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) when this operation executes. Furthermore, the size of the forward [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) is frozen by this call. As a result, the flow is used to ensure that the call to generate the gradient [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) only happens after all writes are executed.\n\nIn the case of dynamically sized TensorArrays, gradient computation should only be performed on read operations that have themselves been chained via flow to occur only after all writes have executed. That way the final size of the forward [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) is known when this operation is called.\n\n\n**A note about the source attribute:**\n\n[TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) gradient calls use an accumulator [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) object. If multiple gradients are calculated and run in the same session, the multiple gradient nodes may accidentally flow through the same accumulator [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array). This double counts and generally breaks the [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) gradient flow.\n\nThe solution is to identify which gradient call this particular [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) gradient is being called in. This is performed by identifying a unique string (e.g. \"gradients\", \"gradients_1\", ...) from the input gradient [Tensor](/versions/r2.1/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor)'s name. This string is used as a suffix when creating the [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) gradient object here (the attribute `source`).\n\nThe attribute `source` is added as a suffix to the forward [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)'s name when performing the creation / lookup, so that each separate gradient calculation gets its own [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) accumulator.\n\nArguments:\n\n- scope: A [Scope](/versions/r2.1/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- handle: The handle to the forward [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array).\n- flow_in: A float scalar that enforces proper chaining of operations.\n- source: The gradient source string, used to decide which gradient [TensorArray](/versions/r2.1/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) to return.\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.1/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) grad_handle\n- [Output](/versions/r2.1/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) flow_out\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [TensorArrayGrad](#classtensorflow_1_1ops_1_1_tensor_array_grad_1a6240f50f9c7efdcf3bf8d48c4218d27b)`(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)` handle, ::`[tensorflow::Input](/versions/r2.1/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` flow_in, StringPiece source)` ||\n\n| ### Public attributes ||\n|-------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| [flow_out](#classtensorflow_1_1ops_1_1_tensor_array_grad_1a2499ef8bb9c633df24389a51f37654da) | `::`[tensorflow::Output](/versions/r2.1/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n| [grad_handle](#classtensorflow_1_1ops_1_1_tensor_array_grad_1ab5be040d777eb52f767d58a83a3a345d) | `::`[tensorflow::Output](/versions/r2.1/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n| [operation](#classtensorflow_1_1ops_1_1_tensor_array_grad_1ae7c0b0022fc4a44d321bf759c55413c2) | [Operation](/versions/r2.1/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n\nPublic attributes\n-----------------\n\n### flow_out\n\n```scdoc\n::tensorflow::Output flow_out\n``` \n\n### grad_handle\n\n```scdoc\n::tensorflow::Output grad_handle\n``` \n\n### operation\n\n```text\nOperation operation\n``` \n\nPublic functions\n----------------\n\n### TensorArrayGrad\n\n```gdscript\n TensorArrayGrad(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input handle,\n ::tensorflow::Input flow_in,\n StringPiece source\n)\n```"]]