Scope
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
מנהל קבוצות של מאפיינים קשורים בעת יצירת Tensorflow Operations, כגון קידומת שם נפוץ.
A Scope
הוא מיכל למאפיינים נפוצים המיושמים על TensorFlow Ops. קוד משתמש רגיל מאתחל Scope
ומספק אותו למחלקות של בניית Operation. לְדוּגמָה:
Scope scope = new Scope(graph);
Constant c = Constant.create(scope, 42);
מחלקה לבניית פעולות רוכשת Scope, ומשתמשת בו כדי להגדיר מאפיינים באופציות הבסיסיות של 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()
...
}
}
היררכיית היקף:
A 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 בוליאני | שווה (Object arg0) |
כיתה אחרונה<?> | getClass () |
int | hashcode () |
ריק סופי | להודיע () |
ריק סופי | הודע הכל () |
חוּט | toString () |
ריק סופי | המתן (ארג0 ארוך, אינט arg1) |
ריק סופי | חכה (ארג0 ארוך) |
ריק סופי | חכה () |
בונים ציבוריים
צור היקף חדש ברמה העליונה.
פרמטרים
env | סביבת הביצוע המשמשת את ה-scope. |
---|
שיטות ציבוריות
מוסיף כל אופרנד ב-controlDependencies כקלט בקרה לבונה המסופק.
פרמטרים
בּוֹנֶה | OperationBuilder להוספת תשומות בקרה |
---|
מחזירה את סביבת הביצוע המשמשת את ההיקף הזה.
מחרוזת ציבורית makeOpName (מחרוזת defaultName)
צור שם ייחודי לאופרטור, תוך שימוש בברירת המחדל שסופקה במידת הצורך.
זה נקרא בדרך כלל רק על ידי כיתות בניית מפעיל.
שיטה זו יוצרת שם ייחודי, המתאים להיקף השם שנשלט על ידי מופע זה. קוד בנייה טיפוסי של מפעיל עשוי להיראות
scope.env().opBuilder("Const", scope.makeOpName("Const"))...
הערה: אם אתה מספק מחלקה מורכבת לבניית מפעיל (כלומר, מחלקה שיוצרת קבוצה של פעולות קשורות על ידי קריאה לקוד בנייה של מפעיל אחר), השם שסופק ישמש כתת-היקף לכל המפעילים הבסיסיים.
פרמטרים
defaultName | שם לאופרטור הבסיסי. |
---|
זורק
חריג טיעון לא חוקי | אם שם ברירת המחדל אינו חוקי. |
---|
היקף ציבורי עם תלות שליטה (בקרות < Operand <?>> שניתן לבצע)
מחזירה היקף חדש שבו לפעולות שנוספו יהיו תלות הבקרה שסופקו.
לאופציות שנוצרו עם היקף זה יהיה יתרון שליטה מכל אחד מהפקדים שסופקו. כל שאר המאפיינים עוברים בירושה מההיקף הנוכחי.
פרמטרים
בקרות | שליטה בתלות עבור פעולות שנוצרו עם ההיקף המוחזר |
---|
מחזיר
- היקף חדש עם תלות הבקרה שסופקה
היקף ציבורי עם שם (מחרוזת opName)
החזר היקף חדש המשתמש בשם שצוין עבור אופציה.
לפעולות שנוצרו בהיקף זה יהיה שם של הטופס name/opName[_suffix]
. זה מאפשר לך לתת שם לאופרטור ספציפי בצורה משמעותית יותר.
השמות חייבים להתאים לביטוי הרגולרי [A-Za-z0-9.][A-Za-z0-9_.\-]*
פרמטרים
opName | שם לאופרטור בהיקף המוחזר |
---|
מחזיר
- Scope חדש המשתמש ב-opName עבור פעולות.
זורק
חריג טיעון לא חוקי | אם השם לא חוקי |
---|
Public Scope withSubScope (מחרוזת childScopeName)
מחזירה היקף חדש שבו פעולות שנוספו יקבלו את קידומת השם שסופקה.
אופציות שנוצרו עם היקף זה יהיו עם name/childScopeName/
בתור הקידומת. השם בפועל יהיה ייחודי בהיקף המוחזר. כל שאר המאפיינים עוברים בירושה מההיקף הנוכחי.
שם הטווח הצאצא חייב להתאים לביטוי הרגולרי [A-Za-z0-9.][A-Za-z0-9_.\-]*
פרמטרים
childScopeName | שם עבור היקף הילד החדש |
---|
זורק
חריג טיעון לא חוקי | אם השם לא חוקי |
---|
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים נוספים, אפשר לקרוא את מדיניות האתר של Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה. חלק מהתוכן הוא ברישיון NumPy.
עדכון אחרון: 2025-07-27 (שעון UTC).
[null,null,["עדכון אחרון: 2025-07-27 (שעון 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.14/api_docs/java/org/tensorflow/op/Scope#Scope(org.tensorflow.ExecutionEnvironment))([ExecutionEnvironment](/versions/r2.14/api_docs/java/org/tensorflow/ExecutionEnvironment) env) Create a new top-level scope. |\n\n### Public Methods\n\n|-------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [OperationBuilder](/versions/r2.14/api_docs/java/org/tensorflow/OperationBuilder) | [applyControlDependencies](/versions/r2.14/api_docs/java/org/tensorflow/op/Scope#applyControlDependencies(org.tensorflow.OperationBuilder))([OperationBuilder](/versions/r2.14/api_docs/java/org/tensorflow/OperationBuilder) builder) Adds each Operand in controlDependencies as a control input to the provided builder. |\n| [ExecutionEnvironment](/versions/r2.14/api_docs/java/org/tensorflow/ExecutionEnvironment) | [env](/versions/r2.14/api_docs/java/org/tensorflow/op/Scope#env())() Returns the execution environment used by this scope. |\n| String | [makeOpName](/versions/r2.14/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.14/api_docs/java/org/tensorflow/op/Scope) | [withControlDependencies](/versions/r2.14/api_docs/java/org/tensorflow/op/Scope#withControlDependencies(java.lang.Iterable\u003corg.tensorflow.Operand\u003c?\u003e\u003e))(Iterable\\\u003c[Operand](/versions/r2.14/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.14/api_docs/java/org/tensorflow/op/Scope) | [withName](/versions/r2.14/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.14/api_docs/java/org/tensorflow/op/Scope) | [withSubScope](/versions/r2.14/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.14/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.14/api_docs/java/org/tensorflow/OperationBuilder)\n**applyControlDependencies**\n([OperationBuilder](/versions/r2.14/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.14/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.14/api_docs/java/org/tensorflow/op/Scope)\n**withControlDependencies**\n(Iterable\\\u003c[Operand](/versions/r2.14/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.14/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.14/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|--------------------------|------------------------|"]]