تحذير: تم إهمال واجهة برمجة التطبيقات هذه وستتم إزالتها في إصدار مستقبلي من TensorFlow بعد استقرار الاستبدال .
Session
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
سائق لتنفيذ Graph
.
يقوم مثيل Session
بتغليف البيئة التي يتم فيها تنفيذ Operation
في Graph
لحساب Tensors
. على سبيل المثال:
// 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()
.
مثيلات الجلسة آمنة لمؤشر الترابط.
الأساليب العامة
فارغ | يغلق () تحرير الموارد المرتبطة بالجلسة. |
الجلسة.عداء | عداء () قم بإنشاء Runner لتنفيذ عمليات الرسم البياني وتقييم Tensors. |
الطرق الموروثة
من فئة java.lang.Object منطقية | يساوي (كائن arg0) |
الدرجة النهائية<?> | الحصول على كلاس () |
كثافة العمليات | رمز التجزئة () |
الفراغ النهائي | إعلام () |
الفراغ النهائي | إعلام الكل () |
خيط | إلى السلسلة () |
الفراغ النهائي | انتظر (طويل arg0، int arg1) |
الفراغ النهائي | انتظر (طويل arg0) |
الفراغ النهائي | انتظر () |
من الواجهة java.lang.AutoCloseable المقاولون العامون
أنشئ جلسة جديدة باستخدام Graph
المرتبط بها.
الجلسة العامة ( الرسم البياني g، بايت[] التكوين)
أنشئ جلسة جديدة باستخدام خيارات Graph
والتكوين المرتبطة بها.
حدود
ز | Graph الذي ستعمل عليه الجلسة التي تم إنشاؤها. |
---|
التكوين | معلمات التكوين للجلسة المحددة كمخزن مؤقت لبروتوكول ConfigProto المتسلسل. |
---|
رميات
IllegalArgumentException | إذا لم يكن التكوين تسلسلًا صالحًا للمخزن المؤقت لبروتوكول ConfigProto. |
---|
الأساليب العامة
إغلاق الفراغ العام ()
تحرير الموارد المرتبطة بالجلسة.
يتم الحظر حتى لا تكون هناك عمليات تنفيذ نشطة (استدعاءات Session.Runner.run()
). الجلسة غير قابلة للاستخدام بعد العودة القريبة.
الجلسة العامة.عداء العداء ()
قم بإنشاء Runner لتنفيذ عمليات الرسم البياني وتقييم Tensors.
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],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."]]