Transform
A type-safe transformation operation that converts input of type I to output of type O.
Transforms are the building blocks of data preprocessing pipelines in SKaiNET. They can be composed together using the then infix function to create complex preprocessing chains while maintaining full type safety.
Design Principles
Type Safety: Generic types I and O ensure that transforms can only be composed when their types are compatible.
Composability: Transforms can be chained using then to create pipelines:
val pipeline = loadImage then resize(224, 224) then toTensor then normalizeContent copied to clipboardShape Awareness: Each transform can compute its output shape from the input shape, enabling shape inference without executing the full pipeline.
Immutability: Transforms should be stateless and immutable. Any configuration should be provided at construction time.
Example Usage
// Define a simple scaling transform
class Scale(private val factor: Float) : Transform<Float, Float> {
override fun apply(input: Float): Float = input * factor
override fun getOutputShape(inputShape: Shape): Shape = inputShape
}
// Compose transforms
val pipeline = Scale(2.0f) then Scale(0.5f)
val result = pipeline.apply(10.0f) // Returns 10.0fParameters
The input type this transform accepts
The output type this transform produces
Inheritors
Functions
Chains an ImageCenterCrop transform that extracts a centered square.
Computes the output shape that would result from applying this transform to data with the given input shape.
Chains a Reshape transform using vararg dimensions.
Chains a Reshape transform.
Chains an ImageResize transform.
Chains an ImageRotate transform.
Chains an ImageToTensor transform that converts the image to a tensor.