Scope
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
จัดการกลุ่มของคุณสมบัติที่เกี่ยวข้องเมื่อสร้างการดำเนินการ Tensorflow เช่น คำนำหน้าชื่อทั่วไป
Scope
คือคอนเทนเนอร์สำหรับคุณสมบัติทั่วไปที่ใช้กับ TensorFlow Ops รหัสผู้ใช้ปกติจะเริ่มต้น Scope
และมอบให้กับคลาสการสร้างการดำเนินการ ตัวอย่างเช่น:
Scope scope = new Scope(graph);
Constant c = Constant.create(scope, 42);
คลาสการสร้างการดำเนินการได้รับขอบเขต และใช้เพื่อตั้งค่าคุณสมบัติบนการดำเนินการ Tensorflow พื้นฐาน ตัวอย่างเช่น:
// An operator class that adds a constant.
public class Constant {
public static Constant create(Scope scope, ...) {
scope.graph().opBuilder(
"Const", scope.makeOpName("Const"))
.setAttr(...)
.build()
...
}
}
ลำดับชั้นของขอบเขต:
Scope
มีวิธีการต่างๆ with()
ที่สร้างขอบเขตใหม่ โดยทั่วไปขอบเขตใหม่จะมีการเปลี่ยนแปลงคุณสมบัติหนึ่งในขณะที่คุณสมบัติอื่นๆ ได้รับการสืบทอดมาจากขอบเขตหลัก
ตัวอย่างการใช้ Constant
ที่นำมาใช้เหมือนเมื่อก่อน:
Scope root = new Scope(graph);
// The linear subscope will generate names like linear/...
Scope linear = Scope.withSubScope("linear");
// This op name will be "linear/W"
Constant.create(linear.withName("W"), ...);
// This op will be "linear/Const", using the default
// name provided by Constant
Constant.create(linear, ...);
// This op will be "linear/Const_1", using the default
// name provided by Constant and making it unique within
// this scope
Constant.create(linear, ...);
วัตถุขอบเขต ไม่ ปลอดภัยสำหรับเธรด
วิธีการสืบทอด
จากคลาส java.lang.Object บูลีน | เท่ากับ (วัตถุ arg0) |
คลาสสุดท้าย<?> | รับคลาส () |
ภายใน | แฮชโค้ด () |
โมฆะสุดท้าย | แจ้ง () |
โมฆะสุดท้าย | แจ้งทั้งหมด () |
สตริง | toString () |
โมฆะสุดท้าย | รอสักครู่ (ยาว arg0, int arg1) |
โมฆะสุดท้าย | รอ (ยาว arg0) |
โมฆะสุดท้าย | รอ () |
คอนสตรัคชั่นสาธารณะ
สร้างขอบเขตระดับบนสุดใหม่
พารามิเตอร์
สิ่งแวดล้อม | สภาพแวดล้อมการดำเนินการที่ใช้โดยขอบเขต |
---|
วิธีการสาธารณะ
เพิ่มตัวดำเนินการแต่ละตัวใน controlDependencies เป็นอินพุตควบคุมให้กับตัวสร้างที่จัดเตรียมไว้
พารามิเตอร์
ผู้สร้าง | OperationBuilder เพื่อเพิ่มอินพุตควบคุม |
---|
ส่งคืนสภาพแวดล้อมการดำเนินการที่ใช้โดยขอบเขตนี้
สาธารณะสตริง makeOpName (สตริง defaultName)
สร้างชื่อที่ไม่ซ้ำกันสำหรับโอเปอเรเตอร์ โดยใช้ค่าเริ่มต้นที่ให้ไว้หากจำเป็น
โดยปกติจะเรียกเฉพาะคลาสการสร้างตัวดำเนินการเท่านั้น
วิธีการนี้จะสร้างชื่อที่ไม่ซ้ำกัน ซึ่งเหมาะสมกับขอบเขตชื่อที่ควบคุมโดยอินสแตนซ์นี้ รหัสอาคารของตัวดำเนินการทั่วไปอาจมีลักษณะดังนี้
scope.env().opBuilder("Const", scope.makeOpName("Const"))...
หมายเหตุ: หากคุณจัดเตรียมคลาสการสร้างตัวดำเนินการแบบผสม (เช่น คลาสที่สร้างชุดของการดำเนินการที่เกี่ยวข้องโดยการเรียกโค้ดการสร้างตัวดำเนินการอื่นๆ) ชื่อที่ให้ไว้จะทำหน้าที่เป็นขอบเขตย่อยสำหรับตัวดำเนินการพื้นฐานทั้งหมด
พารามิเตอร์
ชื่อเริ่มต้น | ชื่อของตัวดำเนินการพื้นฐาน |
---|
การส่งคืน
- ชื่อเฉพาะสำหรับโอเปอเรเตอร์
ขว้าง
ข้อยกเว้นอาร์กิวเมนต์ที่ผิดกฎหมาย | หากชื่อเริ่มต้นไม่ถูกต้อง |
---|
ขอบเขต สาธารณะ ที่มีการควบคุมการพึ่งพา (ควบคุมได้ < ตัวดำเนินการ <?>>)
ส่งกลับขอบเขตใหม่ที่การดำเนินการที่เพิ่มเข้ามาจะมีการขึ้นต่อกันของการควบคุมที่ให้มา
การดำเนินการที่สร้างขึ้นด้วยขอบเขตนี้จะมีขอบเขตการควบคุมจากแต่ละการควบคุมที่ให้มา คุณสมบัติอื่นๆ ทั้งหมดสืบทอดมาจากขอบเขตปัจจุบัน
พารามิเตอร์
การควบคุม | ควบคุมการพึ่งพาสำหรับ ops ที่สร้างขึ้นด้วยขอบเขตที่ส่งคืน |
---|
การส่งคืน
- ขอบเขตใหม่ที่มีการพึ่งพาการควบคุมที่ให้มา
ขอบเขต สาธารณะ withName (สตริง opName)
กลับขอบเขตใหม่ที่ใช้ชื่อที่ให้ไว้สำหรับสหกรณ์
การดำเนินการที่สร้างขึ้นภายในขอบเขตนี้จะมีชื่อของฟอร์ม name/opName[_suffix]
ซึ่งช่วยให้คุณตั้งชื่อโอเปอเรเตอร์เฉพาะเจาะจงให้มีความหมายมากขึ้น
ชื่อต้องตรงกับนิพจน์ทั่วไป [A-Za-z0-9.][A-Za-z0-9_.\-]*
พารามิเตอร์
opName | ชื่อของตัวดำเนินการในขอบเขตที่ส่งคืน |
---|
การส่งคืน
- ขอบเขตใหม่ที่ใช้ opName สำหรับการดำเนินงาน
ขว้าง
ข้อยกเว้นอาร์กิวเมนต์ที่ผิดกฎหมาย | ถ้าชื่อไม่ถูกต้อง |
---|
ขอบเขต สาธารณะ withSubScope (สตริง childScopeName)
ส่งกลับขอบเขตใหม่ที่การดำเนินการที่เพิ่มจะมีคำนำหน้าชื่อที่ให้ไว้
Ops ที่สร้างขึ้นด้วยขอบเขตนี้จะมี name/childScopeName/
เป็นคำนำหน้า ชื่อจริงจะไม่ซ้ำกันในขอบเขตที่ส่งคืน คุณสมบัติอื่นๆ ทั้งหมดสืบทอดมาจากขอบเขตปัจจุบัน
ชื่อขอบเขตย่อยต้องตรงกับนิพจน์ทั่วไป [A-Za-z0-9.][A-Za-z0-9_.\-]*
พารามิเตอร์
ชื่อขอบเขตเด็ก | ชื่อสำหรับขอบเขตลูกใหม่ |
---|
ขว้าง
ข้อยกเว้นอาร์กิวเมนต์ที่ผิดกฎหมาย | ถ้าชื่อไม่ถูกต้อง |
---|
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers ส่วน Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ เนื้อหาบางส่วนได้รับอนุญาตภายใต้ใบอนุญาต NumPy
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[],[],null,["# Scope\n\npublic final class **Scope** \nManages groups of related properties when creating Tensorflow Operations, such as a common name\nprefix.\n\nA `Scope` is a container for common properties applied to TensorFlow Ops. Normal user\ncode initializes a `Scope` and provides it to Operation building classes. For example:\n\n Scope scope = new Scope(graph);\n Constant c = Constant.create(scope, 42);\n \nAn Operation building class acquires a Scope, and uses it to set properties on the underlying\nTensorflow ops. For example:\n\n // An operator class that adds a constant.\n public class Constant {\n public static Constant create(Scope scope, ...) {\n scope.graph().opBuilder(\n \"Const\", scope.makeOpName(\"Const\"))\n .setAttr(...)\n .build()\n ...\n }\n }\n \n**Scope hierarchy:**\n\nA `Scope` provides various `with()` methods that create a new scope. The new scope\ntypically has one property changed while other properties are inherited from the parent scope.\n\nAn example using `Constant` implemented as before:\n\n Scope root = new Scope(graph);\n\n // The linear subscope will generate names like linear/...\n Scope linear = Scope.withSubScope(\"linear\");\n\n // This op name will be \"linear/W\"\n Constant.create(linear.withName(\"W\"), ...);\n\n // This op will be \"linear/Const\", using the default\n // name provided by Constant\n Constant.create(linear, ...);\n\n // This op will be \"linear/Const_1\", using the default\n // name provided by Constant and making it unique within\n // this scope\n Constant.create(linear, ...);\n \nScope objects are **not** thread-safe.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Public Constructors\n\n|---|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | [Scope](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope#Scope(org.tensorflow.ExecutionEnvironment))([ExecutionEnvironment](/versions/r2.11/api_docs/java/org/tensorflow/ExecutionEnvironment) env) Create a new top-level scope. |\n\n### Public Methods\n\n|-------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [OperationBuilder](/versions/r2.11/api_docs/java/org/tensorflow/OperationBuilder) | [applyControlDependencies](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope#applyControlDependencies(org.tensorflow.OperationBuilder))([OperationBuilder](/versions/r2.11/api_docs/java/org/tensorflow/OperationBuilder) builder) Adds each Operand in controlDependencies as a control input to the provided builder. |\n| [ExecutionEnvironment](/versions/r2.11/api_docs/java/org/tensorflow/ExecutionEnvironment) | [env](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope#env())() Returns the execution environment used by this scope. |\n| String | [makeOpName](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope#makeOpName(java.lang.String))(String defaultName) Create a unique name for an operator, using a provided default if necessary. |\n| [Scope](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope) | [withControlDependencies](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope#withControlDependencies(java.lang.Iterable\u003corg.tensorflow.Operand\u003c?\u003e\u003e))(Iterable\\\u003c[Operand](/versions/r2.11/api_docs/java/org/tensorflow/Operand)\\\u003c?\\\u003e\\\u003e controls) Returns a new scope where added operations will have the provided control dependencies. |\n| [Scope](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope) | [withName](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope#withName(java.lang.String))(String opName) Return a new scope that uses the provided name for an op. |\n| [Scope](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope) | [withSubScope](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope#withSubScope(java.lang.String))(String childScopeName) Returns a new scope where added operations will have the provided name prefix. |\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\nPublic Constructors\n-------------------\n\n#### public\n**Scope**\n([ExecutionEnvironment](/versions/r2.11/api_docs/java/org/tensorflow/ExecutionEnvironment) env)\n\nCreate a new top-level scope. \n\n##### Parameters\n\n| env | The execution environment used by the scope. |\n|-----|----------------------------------------------|\n\nPublic Methods\n--------------\n\n#### public [OperationBuilder](/versions/r2.11/api_docs/java/org/tensorflow/OperationBuilder)\n**applyControlDependencies**\n([OperationBuilder](/versions/r2.11/api_docs/java/org/tensorflow/OperationBuilder) builder)\n\nAdds each Operand in controlDependencies as a control input to the provided builder. \n\n##### Parameters\n\n| builder | OperationBuilder to add control inputs to |\n|---------|-------------------------------------------|\n\n#### public [ExecutionEnvironment](/versions/r2.11/api_docs/java/org/tensorflow/ExecutionEnvironment)\n**env**\n()\n\nReturns the execution environment used by this scope. \n\n#### public String\n**makeOpName**\n(String defaultName)\n\nCreate a unique name for an operator, using a provided default if necessary.\n\nThis is normally called only by operator building classes.\n\nThis method generates a unique name, appropriate for the name scope controlled by this\ninstance. Typical operator building code might look like\n\n scope.env().opBuilder(\"Const\", scope.makeOpName(\"Const\"))...\n \n**Note:** if you provide a composite operator building class (i.e, a class that creates a\nset of related operations by calling other operator building code), the provided name will act\nas a subscope to all underlying operators.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| defaultName | name for the underlying operator. |\n|-------------|-----------------------------------|\n\n##### Returns\n\n- unique name for the operator. \n\n##### Throws\n\n| IllegalArgumentException | if the default name is invalid. |\n|--------------------------|---------------------------------|\n\n#### public [Scope](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope)\n**withControlDependencies**\n(Iterable\\\u003c[Operand](/versions/r2.11/api_docs/java/org/tensorflow/Operand)\\\u003c?\\\u003e\\\u003e controls)\n\nReturns a new scope where added operations will have the provided control dependencies.\n\nOps created with this scope will have a control edge from each of the provided controls. All\nother properties are inherited from the current scope.\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| controls | control dependencies for ops created with the returned scope |\n|----------|--------------------------------------------------------------|\n\n##### Returns\n\n- a new scope with the provided control dependencies \n\n#### public [Scope](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope)\n**withName**\n(String opName)\n\nReturn a new scope that uses the provided name for an op.\n\nOperations created within this scope will have a name of the form `name/opName[_suffix]`. This lets you name a specific operator more meaningfully.\n\nNames must match the regular expression `[A-Za-z0-9.][A-Za-z0-9_.\\-]*`\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| opName | name for an operator in the returned scope |\n|--------|--------------------------------------------|\n\n##### Returns\n\n- a new Scope that uses opName for operations. \n\n##### Throws\n\n| IllegalArgumentException | if the name is invalid |\n|--------------------------|------------------------|\n\n#### public [Scope](/versions/r2.11/api_docs/java/org/tensorflow/op/Scope)\n**withSubScope**\n(String childScopeName)\n\nReturns a new scope where added operations will have the provided name prefix.\n\nOps created with this scope will have `name/childScopeName/` as the prefix. The actual\nname will be unique in the returned scope. All other properties are inherited from the current\nscope.\n\nThe child scope name must match the regular expression `[A-Za-z0-9.][A-Za-z0-9_.\\-]*`\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| childScopeName | name for the new child scope |\n|----------------|------------------------------|\n\n##### Returns\n\n- a new subscope \n\n##### Throws\n\n| IllegalArgumentException | if the name is invalid |\n|--------------------------|------------------------|"]]