警告:この API は非推奨であり、置き換えが安定した後の TensorFlow の将来のバージョンでは削除される予定です。
EagerSession.ResourceCleanupStrategy
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
TensorFlow リソースが不要になったときにどのようにクリーンアップするかを制御します。
EagerSession
中に割り当てられたすべてのリソースは、セッションが終了すると削除されます。メモリ不足エラーを防ぐために、セッション中にこれらのリソースをクリーンアップすることも強くお勧めします。たとえば、m 回の反復のループで n 個の操作を実行すると、少なくとも n*m のリソースが割り当てられますが、ほとんどの場合、最後の反復のリソースのみが引き続き使用されます。
EagerSession
インスタンスは、TensorFlow オブジェクトが参照されなくなったときにさまざまな方法で通知できるため、所有していたリソースのクリーンアップに進むことができます。
継承されたメソッド
クラスjava.lang.Enumから最終整数 | 比較先(E arg0) |
整数 | 比較先(オブジェクト arg0) |
最終ブール値 | 等しい(オブジェクト arg0) |
最終クラス<E> | getDeclaringClass () |
最終整数 | ハッシュコード() |
最後の文字列 | 名前() |
最終整数 | 序数() |
弦 | toString () |
static <T extends Enum<T>> T | valueOf (Class<T> arg0, String arg1) |
クラスjava.lang.Objectからブール値 | 等しい(オブジェクト arg0) |
最終クラス<?> | getクラス() |
整数 | ハッシュコード() |
最後の空白 | 通知する() |
最後の空白 | すべて通知() |
弦 | toString () |
最後の空白 | wait (long arg0, int arg1) |
最後の空白 | 待機(長い引数0) |
最後の空白 | 待って() |
インターフェース java.lang.Comparable から抽象整数 | CompareTo (E は Enum<E> arg0 を拡張) |
列挙値
public static Final EagerSession.ResourceCleanupStrategy IN_BACKGROUND
バックグラウンドで実行されている新しいスレッドから未使用のリソースを監視し、削除します。
これは TensorFlow リソースをクリーンアップするための最も信頼性の高いアプローチですが、このタスク専用の追加スレッドを開始して実行するというコストがかかります。各EagerSession
インスタンスには独自のスレッドがあり、セッションが閉じられた場合にのみ停止されます。
この戦略はデフォルトで使用されます。
public static Final EagerSession.ResourceCleanupStrategy ON_SAFE_POINTS
既存のスレッドが別のタスクを完了する前または後に、未使用のリソースを監視し、既存のスレッドから削除します。
TensorFlow ライブラリへの呼び出しがクリーンアップの安全なポイントに達すると、未使用のリソースが解放されます。これは同期的に行われるため、その呼び出しをトリガーしたスレッドが短期間ブロックされる可能性があります。
この戦略は、何らかの理由でクリーンアップに追加のスレッドを割り当てる必要がない場合にのみ使用してください。それ以外の場合は、 IN_BACKGROUND
優先する必要があります。
public static Final EagerSession.ResourceCleanupStrategy ON_SESSION_CLOSE
リソースを削除するのは、セッションが閉じている場合のみにしてください。
セッション中に割り当てられたすべてのリソースは、セッションが明示的に閉じられるまで (または従来の「try-with-resource」手法によって) メモリ内に残ります。リソースのクリーンアップのための追加のタスクは試行されません。
この戦略はメモリ不足エラーを引き起こす可能性があるため、セッションの範囲が少量の操作のみの実行に限定されている場合を除き、その使用はお勧めできません。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-25 UTC。
[null,null,["最終更新日 2025-07-25 UTC。"],[],[],null,["# EagerSession.ResourceCleanupStrategy\n\npublic static final enum **EagerSession.ResourceCleanupStrategy** \nControls how TensorFlow resources are cleaned up when they are no longer needed.\n\nAll resources allocated during an `EagerSession` are deleted when the session is\nclosed. To prevent out-of-memory errors, it is also strongly suggest to cleanup those resources\nduring the session. For example, executing n operations in a loop of m iterations will allocate\na minimum of n\\*m resources while in most cases, only resources of the last iteration are still\nbeing used.\n\n`EagerSession` instances can be notified in different ways when TensorFlow objects are\nno longer being referred, so they can proceed to the cleanup of any resources they owned.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Inherited Methods\n\nFrom class java.lang.Enum \n\n|----------------------------------|---------------------------------------|\n| final int | compareTo(E arg0) |\n| int | compareTo(Object arg0) |\n| final boolean | equals(Object arg0) |\n| final Class\\\u003cE\\\u003e | getDeclaringClass() |\n| final int | hashCode() |\n| final String | name() |\n| final int | ordinal() |\n| String | toString() |\n| static \\\u003cT extends Enum\\\u003cT\\\u003e\\\u003e T | valueOf(Class\\\u003cT\\\u003e arg0, String arg1) |\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFrom interface java.lang.Comparable \n\n|--------------|-------------------------------------|\n| abstract int | compareTo(E extends Enum\\\u003cE\\\u003e arg0) |\n\nEnum Values\n-----------\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**IN_BACKGROUND**\n\nMonitor and delete unused resources from a new thread running in background.\n\nThis is the most reliable approach to cleanup TensorFlow resources, at the cost of\nstarting and running an additional thread dedicated to this task. Each `EagerSession`\ninstance has its own thread, which is stopped only when the session is closed.\n\nThis strategy is used by default.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**ON_SAFE_POINTS**\n\nMonitor and delete unused resources from existing threads, before or after they complete\nanother task.\n\nUnused resources are released when a call to the TensorFlow library reaches a safe point\nfor cleanup. This is done synchronously and might block for a short period of time the thread\nwho triggered that call.\n\nThis strategy should be used only if, for some reasons, no additional thread should be\nallocated for cleanup. Otherwise, [IN_BACKGROUND](/api_docs/java/org/tensorflow/EagerSession.ResourceCleanupStrategy#IN_BACKGROUND) should be preferred.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**ON_SESSION_CLOSE**\n\nOnly delete resources when the session is closed.\n\nAll resources allocated during the session will remained in memory until the session is\nexplicitly closed (or via the traditional \\`try-with-resource\\` technique). No extra task for\nresource cleanup will be attempted.\n\nThis strategy can lead up to out-of-memory errors and its usage is not recommended, unless\nthe scope of the session is limited to execute only a small amount of operations.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]