OperationBuilder

public final class OperationBuilder

A builder for Operations in a Graph.

Instances of an OperationBuilder are not thread-safe.

A builder for adding Operations to a Graph. For example, the following uses the builder to create an operation that produces the constant "3" as its output:

// g is a Graph instance.
 try (Tensor c1 = Tensor.create(3.0f)) {
   g.opBuilder("Constant", "MyConst")
       .setAttr("dtype", c1.dataType())
       .setAttr("value", c1)
       .build();
 }
 

Public Methods

OperationBuilder
addControlInput(Operation control)
Ensure that the operation does not execute before the control operation does.
OperationBuilder
addInput(Output input)
OperationBuilder
Operation
build()
Add the Operation being built to the Graph.
OperationBuilder
setAttr(String name, boolean[] value)
OperationBuilder
setAttr(String name, DataType[] value)
OperationBuilder
setAttr(String name, String value)
OperationBuilder
setAttr(String name, float[] value)
OperationBuilder
setAttr(String name, long value)
OperationBuilder
setAttr(String name, long[] value)
OperationBuilder
setAttr(String name, Tensor value)
OperationBuilder
setAttr(String name, boolean value)
OperationBuilder
setAttr(String name, float value)
OperationBuilder
setAttr(String name, DataType value)
OperationBuilder
setAttr(String name, Tensor[] value)
OperationBuilder
setAttr(String name, byte[] value)
OperationBuilder
setAttr(String name, Shape value)
OperationBuilder
setDevice(String device)

Inherited Methods

Public Methods

public OperationBuilder addControlInput (Operation control)

Ensure that the operation does not execute before the control operation does.

A control input is an Operation that must be executed before running the operation currently being built.

For example, an Assert operation may be added as a control input for this operation. The Assert now behaves as a pre-condition that will always verify itself before running the operation.

Parameters
control operation that must be executed before running this operation.
Returns
  • the OperationBuilder instance for chaining.

public OperationBuilder addInput (Output input)

Parameters
input

public OperationBuilder addInputList (Output[] inputs)

Parameters
inputs

public Operation build ()

Add the Operation being built to the Graph.

The OperationBuilder is not usable after build() returns.

public OperationBuilder setAttr (String name, boolean[] value)

Parameters
name
value

public OperationBuilder setAttr (String name, DataType[] value)

Parameters
name
value

public OperationBuilder setAttr (String name, String value)

Parameters
name
value

public OperationBuilder setAttr (String name, float[] value)

Parameters
name
value

public OperationBuilder setAttr (String name, long value)

Parameters
name
value

public OperationBuilder setAttr (String name, long[] value)

Parameters
name
value

public OperationBuilder setAttr (String name, Tensor value)

Parameters
name
value

public OperationBuilder setAttr (String name, boolean value)

Parameters
name
value

public OperationBuilder setAttr (String name, float value)

Parameters
name
value

public OperationBuilder setAttr (String name, DataType value)

Parameters
name
value

public OperationBuilder setAttr (String name, Tensor[] value)

Parameters
name
value

public OperationBuilder setAttr (String name, byte[] value)

Parameters
name
value

public OperationBuilder setAttr (String name, Shape value)

Parameters
name
value

public OperationBuilder setDevice (String device)

Parameters
device