Package org.tribuo.interop.onnx
Class ImageTransformer
java.lang.Object
org.tribuo.interop.onnx.ImageTransformer
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable
,com.oracle.labs.mlrg.olcut.provenance.Provenancable<com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance>
,Serializable
,ExampleTransformer
,ProtoSerializable<org.tribuo.interop.onnx.protos.ExampleTransformerProto>
Image transformer. Assumes the feature id numbers are linearised ids of the form
[0,0,0] = 0, [1,0,0] = 1, ..., [i,0,0] = i, [0,1,0] = i+1, ..., [i,j,0] = i*j, ...
[0,0,1] = (i*j)+1, ..., [i,j,k] = i*j*k.
ONNX expects images in the format [channels,height,width].
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Protobuf serialization version.Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Constructor Summary
ConstructorDescriptionImageTransformer
(int channels, int height, int width) Constructs an image transformer with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionstatic ImageTransformer
deserializeFromProto
(int version, String className, com.google.protobuf.Any message) Deserialization factory.boolean
com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance
int
hashCode()
void
Used by the OLCUT configuration system, and should not be called by external code.org.tribuo.interop.onnx.protos.ExampleTransformerProto
Serializes this object to a protobuf.toString()
ai.onnxruntime.OnnxTensor
transform
(ai.onnxruntime.OrtEnvironment env, List<SparseVector> vectors) Converts a list ofSparseVector
s representing a batch of features into aOnnxTensor
.ai.onnxruntime.OnnxTensor
transform
(ai.onnxruntime.OrtEnvironment env, SparseVector vector) Converts aSparseVector
representing the features into aOnnxTensor
.
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf serialization version.- See Also:
-
-
Constructor Details
-
ImageTransformer
public ImageTransformer(int channels, int height, int width) Constructs an image transformer with the specified parameters.- Parameters:
channels
- The number of colour channels.height
- The height.width
- The width.
-
-
Method Details
-
postConfig
public void postConfig()Used by the OLCUT configuration system, and should not be called by external code.- Specified by:
postConfig
in interfacecom.oracle.labs.mlrg.olcut.config.Configurable
-
deserializeFromProto
public static ImageTransformer deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException Deserialization factory.- Parameters:
version
- The serialized object version.className
- The class name.message
- The serialized data.- Returns:
- The deserialized object.
- Throws:
com.google.protobuf.InvalidProtocolBufferException
- If the protobuf could not be parsed from themessage
.
-
transform
public ai.onnxruntime.OnnxTensor transform(ai.onnxruntime.OrtEnvironment env, SparseVector vector) throws ai.onnxruntime.OrtException Description copied from interface:ExampleTransformer
Converts aSparseVector
representing the features into aOnnxTensor
.It generates it as a single example minibatch.
- Specified by:
transform
in interfaceExampleTransformer
- Parameters:
env
- The OrtEnvironment to create the tensor in.vector
- The features to convert.- Returns:
- A dense OnnxTensor representing this vector.
- Throws:
ai.onnxruntime.OrtException
- if the transformation failed.
-
transform
public ai.onnxruntime.OnnxTensor transform(ai.onnxruntime.OrtEnvironment env, List<SparseVector> vectors) throws ai.onnxruntime.OrtException Description copied from interface:ExampleTransformer
Converts a list ofSparseVector
s representing a batch of features into aOnnxTensor
.- Specified by:
transform
in interfaceExampleTransformer
- Parameters:
env
- The OrtEnvironment to create the tensor in.vectors
- The batch of features to convert.- Returns:
- A dense OnnxTensor representing this minibatch.
- Throws:
ai.onnxruntime.OrtException
- if the transformation failed.
-
toString
-
equals
-
hashCode
public int hashCode() -
serialize
public org.tribuo.interop.onnx.protos.ExampleTransformerProto serialize()Description copied from interface:ProtoSerializable
Serializes this object to a protobuf.- Specified by:
serialize
in interfaceProtoSerializable<org.tribuo.interop.onnx.protos.ExampleTransformerProto>
- Returns:
- The protobuf.
-
getProvenance
public com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance getProvenance()- Specified by:
getProvenance
in interfacecom.oracle.labs.mlrg.olcut.provenance.Provenancable<com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance>
-