警告:この API は非推奨であり、置き換えが安定した後の TensorFlow の将来のバージョンでは削除される予定です。
Session
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Graph
実行用のドライバー。
Session
インスタンスは、 Tensors
を計算するためにGraph
内のOperation
が実行される環境をカプセル化します。例えば:
// Let's say graph is an instance of the Graph class
// for the computation y = 3 * x
try (Session s = new Session(graph)) {
try (Tensor x = Tensor.create(2.0f);
Tensor y = s.runner().feed("x", x).fetch("y").run().get(0)) {
System.out.println(y.floatValue()); // Will print 6.0f
}
try (Tensor x = Tensor.create(1.1f);
Tensor y = s.runner().feed("x", x).fetch("y").run().get(0)) {
System.out.println(y.floatValue()); // Will print 3.3f
}
}
警告: Session
、 close()
を呼び出して明示的に解放する必要があるリソースを所有しています。
セッションのインスタンスはスレッドセーフです。
パブリックメソッド
空所 | 近い() セッションに関連付けられたリソースを解放します。 |
セッションランナー | ランナー() グラフ操作を実行し、Tensor を評価するための Runner を作成します。 |
継承されたメソッド
クラスjava.lang.Objectからブール値 | 等しい(オブジェクト arg0) |
最終クラス<?> | getClass () |
整数 | ハッシュコード() |
最後の空白 | 通知する() |
最後の空白 | すべて通知() |
弦 | toString () |
最後の空白 | wait (long arg0, int arg1) |
最後の空白 | 待機(長い引数0) |
最後の空白 | 待って() |
インターフェース java.lang.AutoCloseable から パブリックコンストラクター
公開セッション(グラフg)
関連付けられたGraph
を使用して新しいセッションを構築します。
パブリックセッション(グラフg、byte[] 構成)
関連するGraph
と構成オプションを使用して新しいセッションを構築します。
投げる
IllegalArgumentException | 構成が ConfigProto プロトコル バッファの有効なシリアル化ではない場合。 |
---|
パブリックメソッド
public void close ()
セッションに関連付けられたリソースを解放します。
アクティブな実行 ( Session.Runner.run()
呼び出し) がなくなるまでブロックします。 close が戻った後は、セッションは使用できません。
グラフ操作を実行し、Tensor を評価するための Runner を作成します。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-26 UTC。
[null,null,["最終更新日 2025-07-26 UTC。"],[],[],null,["# Session\n\npublic final class **Session** \nDriver for [Graph](/api_docs/java/org/tensorflow/Graph) execution.\n\nA `Session` instance encapsulates the environment in which [Operation](/api_docs/java/org/tensorflow/Operation)s in a\n[Graph](/api_docs/java/org/tensorflow/Graph) are executed to compute [Tensors](/api_docs/java/org/tensorflow/Tensor). For example:\n\n // Let's say graph is an instance of the Graph class\n // for the computation y = 3 * x\n\n try (Session s = new Session(graph)) {\n try (Tensor x = Tensor.create(2.0f);\n Tensor y = s.runner().feed(\"x\", x).fetch(\"y\").run().get(0)) {\n System.out.println(y.floatValue()); // Will print 6.0f\n }\n try (Tensor x = Tensor.create(1.1f);\n Tensor y = s.runner().feed(\"x\", x).fetch(\"y\").run().get(0)) {\n System.out.println(y.floatValue()); // Will print 3.3f\n }\n }\n \n**WARNING:** A `Session` owns resources that **must** be explicitly freed by\ninvoking [close()](/api_docs/java/org/tensorflow/Session#close()).\n\nInstances of a Session are thread-safe.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Nested Classes\n\n|-------|---|---|-------------------------------------------------------------------------------------------------------------------------|\n| class | [Session.Run](/api_docs/java/org/tensorflow/Session.Run) || Output tensors and metadata obtained when executing a session. |\n| class | [Session.Runner](/api_docs/java/org/tensorflow/Session.Runner) || Run [Operation](/api_docs/java/org/tensorflow/Operation)s and evaluate [Tensors](/api_docs/java/org/tensorflow/Tensor). |\n\n### Public Constructors\n\n|---|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | [Session](/api_docs/java/org/tensorflow/Session#Session(org.tensorflow.Graph))([Graph](/api_docs/java/org/tensorflow/Graph) g) Construct a new session with the associated [Graph](/api_docs/java/org/tensorflow/Graph). |\n| | [Session](/api_docs/java/org/tensorflow/Session#Session(org.tensorflow.Graph,%20byte[]))([Graph](/api_docs/java/org/tensorflow/Graph) g, byte\\[\\] config) Construct a new session with the associated [Graph](/api_docs/java/org/tensorflow/Graph) and configuration options. |\n\n### Public Methods\n\n|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|\n| void | [close](/api_docs/java/org/tensorflow/Session#close())() Release resources associated with the Session. |\n| [Session.Runner](/api_docs/java/org/tensorflow/Session.Runner) | [runner](/api_docs/java/org/tensorflow/Session#runner())() Create a Runner to execute graph operations and evaluate Tensors. |\n\n### Inherited Methods\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.AutoCloseable \n\n|---------------|---------|\n| abstract void | close() |\n\nPublic Constructors\n-------------------\n\n#### public\n**Session**\n([Graph](/api_docs/java/org/tensorflow/Graph) g)\n\nConstruct a new session with the associated [Graph](/api_docs/java/org/tensorflow/Graph). \n\n##### Parameters\n\n| g | |\n|---|---|\n\n#### public\n**Session**\n([Graph](/api_docs/java/org/tensorflow/Graph) g, byte\\[\\] config)\n\nConstruct a new session with the associated [Graph](/api_docs/java/org/tensorflow/Graph) and configuration options. \n\n##### Parameters\n\n| g | The [Graph](/api_docs/java/org/tensorflow/Graph) the created Session will operate on. |\n| config | Configuration parameters for the session specified as a serialized [ConfigProto](https://www.tensorflow.org/code/tensorflow/core/protobuf/config.proto) protocol buffer. |\n|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Throws\n\n| IllegalArgumentException | if the config is not a valid serialization of the ConfigProto protocol buffer. |\n|--------------------------|--------------------------------------------------------------------------------|\n\nPublic Methods\n--------------\n\n#### public void\n**close**\n()\n\nRelease resources associated with the Session.\n\nBlocks until there are no active executions ([Session.Runner.run()](/api_docs/java/org/tensorflow/Session.Runner#run()) calls). A Session\nis not usable after close returns.\n\n\u003cbr /\u003e\n\n#### public [Session.Runner](/api_docs/java/org/tensorflow/Session.Runner)\n**runner**\n()\n\nCreate a Runner to execute graph operations and evaluate Tensors."]]