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
ONNXOperators 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
FieldsModifier and TypeFieldDescriptionprotected final TProtobuf reference.protected final ONNXContextThe 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, withotherInputsappend 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, withotherInputsappend 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, withotherInputsappend 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 andotheras a length 2 list toinputs.apply(ONNXOperator op, ONNXRef<?> other, String outputName) Convenience method that callsONNXContext.operation(ONNXOperator, List, String), passing this ONNXRef andotheras a length 2 list toinputs.Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map), passing this ONNXRef andotheras 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.CASToperation, and returning the output node of that op.The name of this object.abstract StringGets 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
-
onnxContext
-
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, withotherInputsappend as subsequent arguments. The other arguments behave as in the analogous method on ONNXContext.- Parameters:
op- An ONNXOperator to add to the graph, takinginputsas input.otherInputs- A list ofONNXRefs created by this instance of ONNXContext.outputs- A list of names that the output nodes ofopshould take.attributes- A map of attributes of the operation, passed toONNXOperator.build(ONNXContext, String, String, Map).- Returns:
- a list of
ONNXNodes 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, takinginputsas input.outputs- A list of names that the output nodes ofopshould take.attributes- A map of attributes of the operation, passed toONNXOperator.build(ONNXContext, String, String, Map).- Returns:
- a list of
ONNXNodes 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, takinginputsas input.- Returns:
- a list of
ONNXNodes 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, takinginputsas input.outputName- A name that the output node ofopwill take.- Returns:
- a list of
ONNXNodes 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, takinginputsas input.attributes- A map of attributes of the operation, passed toONNXOperator.build(ONNXContext, String, String, Map).- Returns:
- a list of
ONNXNodes that are the output nodes ofop.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map), passing this ONNXRef andotheras 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, takinginputsas input.other- A second input argument toopattributes- A map of attributes of the operation, passed toONNXOperator.build(ONNXContext, String, String, Map).- Returns:
- a list of
ONNXNodes that are the output nodes ofop.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String), passing this ONNXRef andotheras a length 2 list toinputs.- Parameters:
op- An ONNXOperator to add to the graph, takinginputsas input.other- A second input argument toopoutputName- A name that the output node ofopwill take.- Returns:
- a list of
ONNXNodes that are the output nodes ofop.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map), passing this ONNXRef andotheras 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, takinginputsas input.other- A second input argument toop- Returns:
- a list of
ONNXNodes that are the output nodes ofop.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map), using this ONNXRef as the first argument toinputs, withotherInputsappend 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, takinginputsas input.others- List of ONNXRefs supplied as inputs toopafter this ONNXRef.- Returns:
- a list of
ONNXNodes that are the output nodes ofop.
-
apply
Convenience method that callsONNXContext.operation(ONNXOperator, List, String, Map), using this ONNXRef as the argument toinputs, withotherInputsappend as subsequent arguments.- Parameters:
op- An ONNXOperator to add to the graph, takinginputsas input.others- List of ONNXRefs supplied as inputs toopafter this ONNXRef.outputName- The name for the constructed node.- Returns:
- a list of
ONNXNodes that are the output nodes ofop.
-
assignTo
Convenience method that callsONNXContext.assignTo(ONNXRef, ONNXRef), using this ONNXRef as the argument toinput.- Type Parameters:
Ret- theONNXReftype 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.CASToperation, and returning the output node of that op. Currently supports only float, double, int, and long, which are specified by their respectiveClassobjects (e.g.,float.class). ThrowsIllegalArgumentExceptionwhen 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.
-