@Namespace(value="tensorflow") @NoOffset public static class tensorflow.Scope extends Pointer
A Scope object represents a set of related TensorFlow ops that have the
same properties such as a common name prefix.
A Scope object is a container for TensorFlow Op properties. Op constructors
get a Scope object as a mandatory first argument and the constructed op
acquires the properties in the object.
A simple example:
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 hierarchy:
The Scope class provides various With<> functions that create a new scope.
The new scope typically has one property changed while other properties are
inherited from the parent scope.
NewSubScope(name) method appends name to the prefix of names for ops
created within the scope, and WithOpName() changes the suffix which
otherwise defaults to the type of the op.
Name examples:
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"
auto b = Variable(linear.WithOpName("b"),
{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 lifetime:
A new scope is created by calling Scope::NewRootScope. This creates some
resources that are shared by all the child scopes that inherit from this
scope, directly or transitively. For instance, a new scope creates a new
Graph object to which operations are added when the new scope or its
children are used by an Op constructor. The new scope also has a Status
object which will be used to indicate errors by Op-constructor functions
called on any child scope. The Op-constructor functions have to check the
scope's status by calling the ok() method before proceeding to construct the
op.
Thread safety:
A Scope object is NOT thread-safe. Threads cannot concurrently call
op-constructor functions on the same Scope object.
| Modifier and Type | Class and Description |
|---|---|
static class |
tensorflow.Scope.Impl |
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator| Constructor and Description |
|---|
Scope(Pointer p)
Pointer cast constructor.
|
Scope(tensorflow.Scope other) |
| Modifier and Type | Method and Description |
|---|---|
tensorflow.Scope |
ClearColocation()
Clear all colocation constraints.
|
tensorflow.Scope |
ColocateWith(tensorflow.Operation op)
Return a new scope.
|
tensorflow.Scope |
ColocateWith(tensorflow.Output out)
Convenience function for above.
|
tensorflow.Operation |
control_deps() |
static tensorflow.Scope |
DisabledShapeInferenceScope() |
tensorflow.Status |
DoShapeInference(tensorflow.Node node) |
tensorflow.Scope |
ExitOnError()
Return a new scope.
|
BytePointer |
GetUniqueNameForOp(BytePointer default_name)
Return a unique name, using default_name if an op name has not been
specified.
|
String |
GetUniqueNameForOp(String default_name) |
tensorflow.Graph |
graph_as_shared_ptr() |
tensorflow.Graph |
graph() |
tensorflow.Scope.Impl |
impl() |
static tensorflow.Scope |
NewRootScope()
Return a new scope.
|
tensorflow.Scope |
NewSubScope(BytePointer child_scope_name)
Return a new scope.
|
tensorflow.Scope |
NewSubScope(String child_scope_name) |
boolean |
ok() |
tensorflow.Scope |
put(tensorflow.Scope other) |
tensorflow.Status |
status() |
tensorflow.Status |
ToGraph(tensorflow.Graph g)
If status() is Status::OK(), construct a Graph object using the default
GraphConstructorOptions, and return Status::OK if graph construction was
successful.
|
tensorflow.Status |
ToGraphDef(tensorflow.GraphDef gdef)
If status() is Status::OK(), convert the Graph object stored in this scope
to a GraphDef proto and return Status::OK().
|
void |
UpdateBuilder(tensorflow.NodeBuilder builder)
Update the builder with properties accumulated in this scope.
|
void |
UpdateStatus(tensorflow.Status s)
Update the status on this scope.
|
tensorflow.Scope |
WithAssignedDevice(BytePointer assigned_device)
Returns a new scope.
|
tensorflow.Scope |
WithAssignedDevice(String assigned_device) |
tensorflow.Scope |
WithControlDependencies(tensorflow.Operation control_deps)
Return a new scope.
|
tensorflow.Scope |
WithControlDependencies(tensorflow.Output control_dep)
Same as above, but convenient to add control dependency on the operation
producing the control_dep output.
|
tensorflow.Scope |
WithDevice(BytePointer device)
Return a new scope.
|
tensorflow.Scope |
WithDevice(String device) |
tensorflow.Scope |
WithKernelLabel(BytePointer kernel_label)
Return a new scope.
|
tensorflow.Scope |
WithKernelLabel(String kernel_label) |
tensorflow.Scope |
WithNoControlDependencies()
Return a new scope.
|
tensorflow.Scope |
WithOpName(BytePointer op_name)
Return a new scope.
|
tensorflow.Scope |
WithOpName(String op_name) |
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, hashCode, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetof, parseBytes, physicalBytes, position, position, put, realloc, setNull, sizeof, toString, totalBytes, totalPhysicalBytes, withDeallocator, zeropublic Scope(Pointer p)
Pointer.Pointer(Pointer).public Scope(@Const @ByRef tensorflow.Scope other)
@ByRef @Name(value="operator =") public tensorflow.Scope put(@Const @ByRef tensorflow.Scope other)
@ByVal public static tensorflow.Scope NewRootScope()
@ByVal public tensorflow.Scope NewSubScope(@StdString BytePointer child_scope_name)
name/child_scope_name as the prefix. The actual name will be unique
in the current scope. All other properties are inherited from the current
scope. If child_scope_name is empty, the / is elided.@ByVal public tensorflow.Scope NewSubScope(@StdString String child_scope_name)
@ByVal public tensorflow.Scope WithOpName(@StdString BytePointer op_name)
name/op_name[_suffix].@ByVal public tensorflow.Scope WithOpName(@StdString String op_name)
@ByVal public tensorflow.Scope WithControlDependencies(@tensorflow.ArraySlice tensorflow.Operation control_deps)
@ByVal public tensorflow.Scope WithControlDependencies(@Const @ByRef tensorflow.Output control_dep)
@ByVal public tensorflow.Scope WithNoControlDependencies()
@ByVal public tensorflow.Scope WithDevice(@StdString BytePointer device)
@ByVal public tensorflow.Scope WithDevice(@StdString String device)
@ByVal public tensorflow.Scope WithAssignedDevice(@StdString BytePointer assigned_device)
assigned_device.@ByVal public tensorflow.Scope WithAssignedDevice(@StdString String assigned_device)
@ByVal public tensorflow.Scope ColocateWith(@Const @ByRef tensorflow.Operation op)
@ByVal public tensorflow.Scope ColocateWith(@Const @ByRef tensorflow.Output out)
@ByVal public tensorflow.Scope ClearColocation()
@ByVal public tensorflow.Scope ExitOnError()
@ByVal public tensorflow.Scope WithKernelLabel(@StdString BytePointer kernel_label)
@ByVal public tensorflow.Scope WithKernelLabel(@StdString String kernel_label)
@StdString public BytePointer GetUniqueNameForOp(@StdString BytePointer default_name)
@StdString public String GetUniqueNameForOp(@StdString String default_name)
public void UpdateStatus(@Const @ByVal tensorflow.Status s)
public void UpdateBuilder(tensorflow.NodeBuilder builder)
public tensorflow.Graph graph()
@SharedPtr public tensorflow.Graph graph_as_shared_ptr()
@ByVal public tensorflow.Status status()
@ByVal public tensorflow.Status ToGraphDef(tensorflow.GraphDef gdef)
@ByVal public tensorflow.Status ToGraph(tensorflow.Graph g)
@ByVal public tensorflow.Status DoShapeInference(tensorflow.Node node)
@ByVal public static tensorflow.Scope DisabledShapeInferenceScope()
@StdVector public tensorflow.Operation control_deps()
public tensorflow.Scope.Impl impl()
Copyright © 2019. All rights reserved.