Package org.tribuo.util.onnx
Class ONNXRef<T extends com.google.protobuf.GeneratedMessageV3>
java.lang.Object
org.tribuo.util.onnx.ONNXRef<T>
- Type Parameters:
T
- The protobuf type this reference generates.
- Direct Known Subclasses:
ONNXInitializer
,ONNXNode
,ONNXPlaceholder
An abstract reference that represents both a node in an ONNX computation graph and a container for a specific ONNX
proto object that denotes that node. In its role as the former it provides a fluent interface for applying
ONNXOperator
s to ONNXRef
instances. ONNXRef instances are ultimately created by an ONNXContext
instance, and ONNXRefs created by different instances of ONNXContext are incompatible. All ONNX proto objects
produced by calling apply
methods on ONNXRefs are added to a OnnxMl.GraphProto
field
in their governing ONNXContext. Instances of ONNXRef have a backreference to the ONNXContext that created them and
can thus be passed around without needing to pass their governing context as well.
N.B. This class will be sealed once the library is updated past Java 8. Users should not subclass this class.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final T
Protobuf reference.protected final ONNXContext
The ONNX context. -
Method Summary
Modifier and TypeMethodDescriptionapply
(ONNXOperator op) Convenience method that callsONNXContext.operation(ONNXOperator, List, String)
, using this ONNXRef as the argument toinputs
.apply
(ONNXOperator op, String outputName) Convenience method that callsONNXContext.operation(ONNXOperator, List, String)
, using this ONNXRef as the argument toinputs
.Convenience method that callsONNXContext.operation(ONNXOperator, List, List, Map)
, using this ONNXRef as the argument toinputs
.apply
(ONNXOperator op, List<ONNXRef<?>> others) Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map)
, using this ONNXRef as the first argument toinputs
, withotherInputs
append as subsequent arguments.apply
(ONNXOperator op, List<ONNXRef<?>> others, String outputName) Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map)
, using this ONNXRef as the argument toinputs
, withotherInputs
append as subsequent arguments.apply
(ONNXOperator op, List<ONNXRef<?>> otherInputs, List<String> outputs, Map<String, Object> attributes) Convenience method that callsONNXContext.operation(ONNXOperator, List, List, Map)
, using this ONNXRef as the first argument toinputs
, withotherInputs
append as subsequent arguments.apply
(ONNXOperator op, Map<String, Object> attributes) Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map)
, using this ONNXRef as the argument toinputs
.apply
(ONNXOperator op, ONNXRef<?> other) Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map)
, passing this ONNXRef andother
as a length 2 list toinputs
.apply
(ONNXOperator op, ONNXRef<?> other, String outputName) Convenience method that callsONNXContext.operation(ONNXOperator, List, String)
, passing this ONNXRef andother
as a length 2 list toinputs
.Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map)
, passing this ONNXRef andother
as a length 2 list toinputs
.<Ret extends ONNXRef<?>>
RetassignTo
(Ret output) Convenience method that callsONNXContext.assignTo(ONNXRef, ONNXRef)
, using this ONNXRef as the argument toinput
.Casts this ONNXRef to a different type using theONNXOperators.CAST
operation, and returning the output node of that op.The name of this object.abstract String
Gets the output name of this object.The context this reference operates in.
-
Field Details
-
backRef
Protobuf reference. -
context
The ONNX context.
-
-
Method Details
-
getReference
Gets the output name of this object.- Returns:
- The output name.
-
getBaseName
The name of this object.- Returns:
- The name.
-
onnxContext
The context this reference operates in.- Returns:
- The context.
-
apply
public List<ONNXNode> apply(ONNXOperator op, List<ONNXRef<?>> otherInputs, List<String> outputs, Map<String, Object> attributes) Convenience method that callsONNXContext.operation(ONNXOperator, List, List, Map)
, using this ONNXRef as the first argument toinputs
, withotherInputs
append as subsequent arguments. The other arguments behave as in the analogous method on ONNXContext.- Parameters:
op
- An ONNXOperator to add to the graph, takinginputs
as input.otherInputs
- A list ofONNXRef
s created by this instance of ONNXContext.outputs
- A list of names that the output nodes ofop
should take.attributes
- A map of attributes of the operation, passed toONNXOperator.build(ONNXContext, String, String, Map)
.- Returns:
- a list of
ONNXNode
s that are the output nodes ofop
.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, List, Map)
, using this ONNXRef as the argument toinputs
. The other arguments behave as in the analogous method on ONNXContext.- Parameters:
op
- An ONNXOperator to add to the graph, takinginputs
as input.outputs
- A list of names that the output nodes ofop
should take.attributes
- A map of attributes of the operation, passed toONNXOperator.build(ONNXContext, String, String, Map)
.- Returns:
- a list of
ONNXNode
s that are the output nodes ofop
.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String)
, using this ONNXRef as the argument toinputs
. Output names are generated based on theONNXOperator.getOpName()
and the name of the input nodes.- Parameters:
op
- An ONNXOperator to add to the graph, takinginputs
as input.- Returns:
- a list of
ONNXNode
s that are the output nodes ofop
.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String)
, using this ONNXRef as the argument toinputs
.- Parameters:
op
- An ONNXOperator to add to the graph, takinginputs
as input.outputName
- A name that the output node ofop
will take.- Returns:
- a list of
ONNXNode
s that are the output nodes ofop
.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map)
, using this ONNXRef as the argument toinputs
. Output names are generated based on theONNXOperator.getOpName()
and the name of the input nodes.- Parameters:
op
- An ONNXOperator to add to the graph, takinginputs
as input.attributes
- A map of attributes of the operation, passed toONNXOperator.build(ONNXContext, String, String, Map)
.- Returns:
- a list of
ONNXNode
s that are the output nodes ofop
.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map)
, passing this ONNXRef andother
as a length 2 list toinputs
. The other arguments behave as in the analogous method on ONNXContext. Output names are generated based on theONNXOperator.getOpName()
and the name of the input nodes.- Parameters:
op
- An ONNXOperator to add to the graph, takinginputs
as input.other
- A second input argument toop
attributes
- A map of attributes of the operation, passed toONNXOperator.build(ONNXContext, String, String, Map)
.- Returns:
- a list of
ONNXNode
s that are the output nodes ofop
.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String)
, passing this ONNXRef andother
as a length 2 list toinputs
.- Parameters:
op
- An ONNXOperator to add to the graph, takinginputs
as input.other
- A second input argument toop
outputName
- A name that the output node ofop
will take.- Returns:
- a list of
ONNXNode
s that are the output nodes ofop
.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map)
, passing this ONNXRef andother
as a length 2 list toinputs
. Output names are generated based on theONNXOperator.getOpName()
and the name of the input nodes.- Parameters:
op
- An ONNXOperator to add to the graph, takinginputs
as input.other
- A second input argument toop
- Returns:
- a list of
ONNXNode
s that are the output nodes ofop
.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map)
, using this ONNXRef as the first argument toinputs
, withotherInputs
append as subsequent arguments. Output names are generated based on theONNXOperator.getOpName()
and the name of the input nodes.- Parameters:
op
- An ONNXOperator to add to the graph, takinginputs
as input.others
- List of ONNXRefs supplied as inputs toop
after this ONNXRef.- Returns:
- a list of
ONNXNode
s that are the output nodes ofop
.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map)
, using this ONNXRef as the argument toinputs
, withotherInputs
append as subsequent arguments.- Parameters:
op
- An ONNXOperator to add to the graph, takinginputs
as input.others
- List of ONNXRefs supplied as inputs toop
after this ONNXRef.outputName
- The name for the constructed node.- Returns:
- a list of
ONNXNode
s that are the output nodes ofop
.
-
assignTo
Convenience method that callsONNXContext.assignTo(ONNXRef, ONNXRef)
, using this ONNXRef as the argument toinput
.- Type Parameters:
Ret
- theONNXRef
type of the output.- Parameters:
output
- The output node / left-hand side of the assignment- Returns:
- the output node that was assigned to.
-
cast
Casts this ONNXRef to a different type using theONNXOperators.CAST
operation, and returning the output node of that op. Currently supports only float, double, int, and long, which are specified by their respectiveClass
objects (e.g.,float.class
). ThrowsIllegalArgumentException
when an unsupported cast is requested.- Parameters:
clazz
- The class object specifying the type to cast to.- Returns:
- An ONNXRef representing this object cast into the requested type.
-