텐서플로우:: 범위

#include <scope.h>

Scope 객체는 일반 이름 접두사와 같은 속성이 동일한 관련 TensorFlow 작업 집합을 나타냅니다.

요약

Scope 객체는 TensorFlow Op 속성의 컨테이너입니다. Op 생성자는 필수 첫 번째 인수로 Scope 개체를 가져오고 생성된 op는 개체의 속성을 얻습니다.

간단한 예:

using namespace ops;
Scope root = Scope::NewRootScope();
auto c1 = Const(root, { {1, 1} });
auto m = MatMul(root, c1, { {41}, {1} });
GraphDef gdef;
Status s = root.ToGraphDef(&gdef);
if (!s.ok()) { ... }

범위 계층 구조:

Scope 클래스는 새 범위를 생성하는 다양한 With<> 함수를 제공합니다. 새 범위에는 일반적으로 하나의 속성이 변경되고 다른 속성은 상위 범위에서 상속됩니다. NewSubScope(name) 메서드는 범위 내에서 생성된 작업 이름의 접두사에 name 추가하고 WithOpName()은 작업 유형의 기본값인 접미사를 변경합니다.

이름 예:

Scope root = Scope::NewRootScope();
Scope linear = root.NewSubScope("linear");
// W will be named "linear/W"
auto W = Variable(linear.WithOpName("W"),
                  {2, 2}, DT_FLOAT);
// b will be named "linear/b_3"
int idx = 3;
auto b = Variable(linear.WithOpName("b_", idx),
                  {2}, DT_FLOAT);
auto x = Const(linear, {...});  // name: "linear/Const"
auto m = MatMul(linear, x, W);  // name: "linear/MatMul"
auto r = BiasAdd(linear, m, b); // name: "linear/BiasAdd"

범위 수명:

Scope::NewRootScope 를 호출하여 새 범위가 생성됩니다. 이렇게 하면 이 범위에서 직접 또는 전이적으로 상속되는 모든 하위 범위에서 공유되는 일부 리소스가 생성됩니다. 예를 들어, 새 범위는 Op 생성자가 새 범위나 해당 하위 범위를 사용할 때 작업이 추가되는 새 Graph 개체를 만듭니다. 새 범위에는 하위 범위에서 호출되는 Op 생성자 함수에 의해 오류를 나타내는 데 사용되는 Status 개체도 있습니다. Op 생성자 함수는 op 구성을 진행하기 전에 ok() 메서드를 호출하여 범위의 상태를 확인해야 합니다.

스레드 안전성:

Scope 개체는 스레드로부터 안전하지 않습니다. 스레드는 동일한 Scope 개체에서 연산 생성자 함수를 동시에 호출할 수 없습니다.

생성자와 소멸자

Scope (const Scope & other)
~Scope ()

공공 기능

ClearColocation () const
모든 코로케이션 제약 조건을 지웁니다.
ColocateWith (const Operation & op) const
새 범위를 반환합니다.
ColocateWith (const Output & out) const
위의 편의 기능.
ExitOnError () const
새 범위를 반환합니다.
GetCompositeOpScopes (const string & composite_op_name) const
GetUniqueNameForOp (const string & default_name) const
string
작업 이름이 지정되지 않은 경우 default_name을 사용하여 고유한 이름을 반환합니다.
NewSubScope (const string & child_scope_name) const
새 범위를 반환합니다.
ToGraphDef (GraphDef *gdef) const
status()가 Status::OK()인 경우 이 범위에 저장된 Graph 개체를 GraphDef proto로 변환하고 Status::OK()를 반환합니다.
UpdateStatus (const Status & s) const
void
이 범위의 상태를 업데이트하세요.
WithAssignedDevice (const string & assigned_device) const
새로운 범위를 반환합니다.
WithControlDependencies (const gtl::ArraySlice< Operation > & control_deps) const
새 범위를 반환합니다.
WithControlDependencies (const Output & control_dep) const
위와 동일하지만 control_dep 출력을 생성하는 작업에 제어 종속성을 추가하는 것이 편리합니다.
WithDevice (const string & device) const
새 범위를 반환합니다.
WithKernelLabel (const string & kernel_label) const
새 범위를 반환합니다.
WithNoControlDependencies () const
새 범위를 반환합니다.
WithOpName (Ty... fragments) const
새 범위를 반환합니다.
WithXlaCluster (const string & xla_cluster) const
새로운 범위를 반환합니다.
control_deps () const
const std::vector< Operation > &
graph () const
Graph *
graph_as_shared_ptr () const
std::shared_ptr< Graph >
ok () const
bool
operator= (const Scope & other)
status () const

공개 정적 함수

NewRootScope ()
새 범위를 반환합니다.

공공 기능

ClearColocation

Scope ClearColocation() const 

모든 코로케이션 제약 조건을 지웁니다.

함께 배치하다

Scope ColocateWith(
  const Operation & op
) const 

새 범위를 반환합니다.

반환된 범위 내에서 생성된 모든 작업은 작업이 배치된 장치에 같은 위치에 배치됩니다. 참고: 이 기능은 장치에 대한 작업 배치를 제어하는 ​​데에만 내부 라이브러리를 사용하기 위한 것입니다. 장치 배치 구현은 변경될 수 있으므로 공개 사용은 권장되지 않습니다.

함께 배치하다

Scope ColocateWith(
  const Output & out
) const 

위의 편의 기능.

종료 시 오류

Scope ExitOnError() const 

새 범위를 반환합니다.

반환된 범위를 범위 인수로 사용하는 op 생성자 함수는 범위에 상태를 설정하는 대신 오류가 감지되는 즉시 종료됩니다.

GetCompositeOpScopes

CompositeOpScopes GetCompositeOpScopes(
  const string & composite_op_name
) const 

GetUniqueNameForOp

string GetUniqueNameForOp(
  const string & default_name
) const 

작업 이름이 지정되지 않은 경우 default_name을 사용하여 고유한 이름을 반환합니다.

새로운 하위 범위

Scope NewSubScope(
  const string & child_scope_name
) const 

새 범위를 반환합니다.

이 범위로 생성된 작업에는 접두사로 name/child_scope_name 포함됩니다. 실제 이름은 현재 범위에서 고유합니다. 다른 모든 속성은 현재 범위에서 상속됩니다. child_scope_name 비어 있으면 / 생략됩니다.

범위

 Scope(
  const Scope & other
)

ToGraphDef

Status ToGraphDef(
  GraphDef *gdef
) const 

status()가 Status::OK()인 경우 이 범위에 저장된 Graph 개체를 GraphDef proto로 변환하고 Status::OK()를 반환합니다.

그렇지 않으면 GraphDef 변환을 수행하지 않고 오류 상태를 그대로 반환합니다.

업데이트 상태

void UpdateStatus(
  const Status & s
) const 

이 범위의 상태를 업데이트하세요.

참고: 상태 개체는 이 범위의 모든 하위 항목 간에 공유됩니다. 결과 상태가 Status::OK()가 아니고 이 범위에 exit_on_error_가 설정된 경우 이 함수는 LOG(FATAL)를 호출하여 종료됩니다.

할당된 장치 포함

Scope WithAssignedDevice(
  const string & assigned_device
) const 

새로운 범위를 반환합니다.

반환된 범위 내에서 생성된 모든 작업에는 할당된 장치가 assigned_device 로 설정됩니다.

WithControlDependency

Scope WithControlDependencies(
  const gtl::ArraySlice< Operation > & control_deps
) const 

새 범위를 반환합니다.

반환된 범위 내에서 생성된 모든 작업은 제어 종속성으로 control_deps 벡터의 작업 통합과 현재 범위의 제어 종속성을 갖습니다.

WithControlDependency

Scope WithControlDependencies(
  const Output & control_dep
) const 

위와 동일하지만 control_dep 출력을 생성하는 작업에 제어 종속성을 추가하는 것이 편리합니다.

WithDevice

Scope WithDevice(
  const string & device
) const 

새 범위를 반환합니다.

반환된 범위 내에서 생성된 모든 작업의 ​​장치 필드는 'device'로 설정됩니다.

KernelLabel 사용

Scope WithKernelLabel(
  const string & kernel_label
) const 

새 범위를 반환합니다.

새로운 범위로 생성된 모든 작업은 '_kernel' 속성 값으로 kernel_label을 갖습니다.

WithNoControl종속성

Scope WithNoControlDependencies() const 

새 범위를 반환합니다.

반환된 범위 내에서 생성된 모든 작업은 다른 작업에 대한 제어 종속성을 갖지 않습니다.

WithOpName

Scope WithOpName(
  Ty... fragments
) const 

새 범위를 반환합니다.

반환된 범위 내에서 생성된 모든 작업은 name/StrCat(fragments...)[_suffix] 형식의 이름을 갖습니다.

WithXlaCluster

Scope WithXlaCluster(
  const string & xla_cluster
) const 

새로운 범위를 반환합니다.

반환된 범위 내에서 생성된 모든 작업의 ​​_XlaCluster 속성은 xla_cluster 로 설정됩니다.

control_deps

const std::vector< Operation > & control_deps() const 

그래프

Graph * graph() const 

graph_as_shared_ptr

std::shared_ptr< Graph > graph_as_shared_ptr() const 

좋아요

bool ok() const 

연산자=

Scope & operator=(
  const Scope & other
)

상태

Status status() const 

~범위

 ~Scope()

공개 정적 함수

NewRootScope

Scope NewRootScope()

새 범위를 반환합니다.

그러면 새 그래프가 생성되고 이 그래프에 구성된 모든 작업은 반환된 개체를 "루트" 범위로 사용해야 합니다.