Scope
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
일반 이름 접두사와 같은 Tensorflow 작업을 생성할 때 관련 속성 그룹을 관리합니다.
Scope
TensorFlow Ops에 적용되는 공통 속성에 대한 컨테이너입니다. 일반 사용자 코드는 Scope
초기화하고 이를 Operation 빌딩 클래스에 제공합니다. 예를 들어:
Scope scope = new Scope(graph);
Constant c = Constant.create(scope, 42);
Operation 빌딩 클래스는 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()
...
}
}
범위 계층 구조:
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) |
마지막 수업<?> | getClass () |
정수 | 해시코드 () |
최종 무효 | 알림 () |
최종 무효 | 통지모두 () |
끈 | toString () |
최종 무효 | 대기 (long arg0, int arg1) |
최종 무효 | 기다리세요 (긴 arg0) |
최종 무효 | 기다리다 () |
공개 방법
제공된 빌더에 제어 입력으로 controlDependency의 각 피연산자를 추가합니다.
매개변수
건축업자 | 제어 입력을 추가하는 OperationBuilder |
---|
이 범위에서 사용되는 실행 환경을 반환합니다.
공개 문자열 makeOpName (문자열 defaultName)
필요한 경우 제공된 기본값을 사용하여 연산자의 고유한 이름을 만듭니다.
이는 일반적으로 연산자 구축 클래스에 의해서만 호출됩니다.
이 메서드는 이 인스턴스가 제어하는 이름 범위에 적합한 고유한 이름을 생성합니다. 일반적인 운영자 건물 코드는 다음과 같습니다.
scope.env().opBuilder("Const", scope.makeOpName("Const"))...
참고: 복합 연산자 작성 클래스(예: 다른 연산자 작성 코드를 호출하여 관련 작업 세트를 생성하는 클래스)를 제공하는 경우 제공된 이름은 모든 기본 연산자에 대한 하위 범위 역할을 합니다.
던지기
IllegalArgumentException | 기본 이름이 유효하지 않은 경우. |
---|
public Scope withControlDependency (Iterable< Operand <?>> 컨트롤)
추가된 작업에 제공된 제어 종속성이 있는 새 범위를 반환합니다.
이 범위로 생성된 Op는 제공된 각 컨트롤의 컨트롤 에지를 갖게 됩니다. 다른 모든 속성은 현재 범위에서 상속됩니다.
매개변수
통제 수단 | 반환된 범위로 생성된 작업에 대한 제어 종속성 |
---|
공개 범위 withName (문자열 opName)
작업에 대해 제공된 이름을 사용하는 새 범위를 반환합니다.
이 범위 내에서 생성된 작업은 name/opName[_suffix]
형식의 이름을 갖습니다. 이를 통해 특정 연산자의 이름을 보다 의미 있게 지정할 수 있습니다.
이름은 정규식 [A-Za-z0-9.][A-Za-z0-9_.\-]*
와 일치해야 합니다.
매개변수
opName | 반환된 범위에 있는 연산자의 이름 |
---|
던지기
IllegalArgumentException | 이름이 유효하지 않은 경우 |
---|
공개 범위 withSubScope (문자열 childScopeName)
추가된 작업에 제공된 이름 접두사가 포함되는 새 범위를 반환합니다.
이 범위로 생성된 작업에는 접두사로 name/childScopeName/
이 포함됩니다. 실제 이름은 반환된 범위에서 고유합니다. 다른 모든 속성은 현재 범위에서 상속됩니다.
하위 범위 이름은 정규식 [A-Za-z0-9.][A-Za-z0-9_.\-]*
와 일치해야 합니다.
매개변수
childScopeName | 새 하위 범위의 이름 |
---|
던지기
IllegalArgumentException | 이름이 유효하지 않은 경우 |
---|
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 크리에이티브 커먼즈 저작자 표시 라이선스 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 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|--------------------------|------------------------|"]]