Scope
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Gestisce gruppi di proprietà correlate durante la creazione di operazioni Tensorflow, ad esempio un prefisso di nome comune.
Un Scope
è un contenitore per le proprietà comuni applicate a TensorFlow Ops. Il codice utente normale inizializza uno Scope
e lo fornisce alle classi di costruzione Operation. Per esempio:
Scope scope = new Scope(graph);
Constant c = Constant.create(scope, 42);
Una classe di creazione di operazioni acquisisce un ambito e lo utilizza per impostare le proprietà sulle operazioni Tensorflow sottostanti. Per esempio:
// 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()
...
}
}
Gerarchia dell'ambito:
Uno Scope
fornisce vari metodi with()
che creano un nuovo ambito. Nel nuovo ambito in genere viene modificata una proprietà mentre le altre proprietà vengono ereditate dall'ambito padre.
Un esempio che utilizza Constant
implementato come prima:
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, ...);
Gli oggetti ambito non sono thread-safe.
Metodi pubblici
OperationBuilder | |
Ambiente di esecuzione | ambiente () Restituisce l'ambiente di esecuzione utilizzato da questo ambito. |
Corda | makeOpName (Stringa defaultName) Crea un nome univoco per un operatore, utilizzando un valore predefinito fornito, se necessario. |
Ambito | withControlDependencies (controlli Iterable< Operando <?>>) Restituisce un nuovo ambito in cui le operazioni aggiunte avranno le dipendenze di controllo fornite. |
Ambito | withName (String opName) Restituisce un nuovo ambito che utilizza il nome fornito per un'operazione. |
Ambito | withSubScope (Stringa childScopeName) Restituisce un nuovo ambito in cui le operazioni aggiunte avranno il prefisso del nome fornito. |
Metodi ereditati
Dalla classe java.lang.Object booleano | è uguale a (Oggetto arg0) |
Classe finale<?> | getClass () |
int | codicehash () |
vuoto finale | avvisare () |
vuoto finale | notificaTutti () |
Corda | aStringa () |
vuoto finale | attendere (lungo arg0, int arg1) |
vuoto finale | aspetta (lungo arg0) |
vuoto finale | Aspettare () |
Costruttori pubblici
Crea un nuovo ambito di primo livello.
Parametri
ambi | L'ambiente di esecuzione utilizzato dall'ambito. |
---|
Metodi pubblici
Aggiunge ogni operando in controlDependencies come input di controllo al builder fornito.
Parametri
costruttore | OperationBuilder a cui aggiungere input di controllo |
---|
Restituisce l'ambiente di esecuzione utilizzato da questo ambito.
stringa pubblica makeOpName (stringa defaultName)
Crea un nome univoco per un operatore, utilizzando un valore predefinito fornito, se necessario.
Questo viene normalmente chiamato solo dalle classi di costruzione degli operatori.
Questo metodo genera un nome univoco, appropriato per l'ambito del nome controllato da questa istanza. Potrebbe essere simile un tipico codice di costruzione dell'operatore
scope.env().opBuilder("Const", scope.makeOpName("Const"))...
Nota: se fornisci una classe di creazione di operatori compositi (ovvero, una classe che crea un insieme di operazioni correlate chiamando un altro codice di creazione di operatori), il nome fornito fungerà da ambito secondario per tutti gli operatori sottostanti.
Parametri
defaultName | nome per l'operatore sottostante. |
---|
Ritorni
- nome univoco per l'operatore.
Lancia
IllegalArgumentException | se il nome predefinito non è valido. |
---|
ambito pubblico con ControlDependencies (controlli Iterable< Operand <?>>)
Restituisce un nuovo ambito in cui le operazioni aggiunte avranno le dipendenze di controllo fornite.
Le operazioni create con questo ambito avranno un vantaggio di controllo da ciascuno dei controlli forniti. Tutte le altre proprietà vengono ereditate dall'ambito corrente.
Parametri
controlli | dipendenze di controllo per le operazioni create con l'ambito restituito |
---|
Ritorni
- un nuovo ambito con le dipendenze di controllo fornite
Ambito pubblico con Nome (String opName)
Restituisce un nuovo ambito che utilizza il nome fornito per un'operazione.
Le operazioni create in questo ambito avranno un nome nel formato name/opName[_suffix]
. Ciò ti consente di nominare un operatore specifico in modo più significativo.
I nomi devono corrispondere all'espressione regolare [A-Za-z0-9.][A-Za-z0-9_.\-]*
Parametri
opNome | nome per un operatore nell'ambito restituito |
---|
Ritorni
- un nuovo ambito che utilizza opName per le operazioni.
Lancia
IllegalArgumentException | se il nome non è valido |
---|
Ambito pubblico conSubScope (String childScopeName)
Restituisce un nuovo ambito in cui le operazioni aggiunte avranno il prefisso del nome fornito.
Le operazioni create con questo ambito avranno name/childScopeName/
come prefisso. Il nome effettivo sarà univoco nell'ambito restituito. Tutte le altre proprietà vengono ereditate dall'ambito corrente.
Il nome dell'ambito figlio deve corrispondere all'espressione regolare [A-Za-z0-9.][A-Za-z0-9_.\-]*
Parametri
childScopeName | nome per il nuovo ambito figlio |
---|
Lancia
IllegalArgumentException | se il nome non è valido |
---|
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate. Alcuni contenuti sono concessi in base alla licenza NumPy.
Ultimo aggiornamento 2025-07-26 UTC.
[null,null,["Ultimo aggiornamento 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|--------------------------|------------------------|"]]