Skip to main content

//clika-runtime/io.clika.runtime/ImageProcessor

ImageProcessor

[common]
class ImageProcessor

A configuration-driven image preprocessor: convert to RGB, resize, center-crop, rescale, normalize and pad, as a model's preprocessor_config.json states them, to a [H, W, C] Float32 tensor (channels-last). Load one from a model directory, or build one from the common knobs with fromArgs. AutoCloseable: close releases it.

ImageProcessor.fromHuggingface("/path/to/model").use { processor ->
val pixels = processor.process("/path/photo.jpg") // [H, W, 3] Float32
}

Types​

NameSummary
Companion[common]
object Companion

Functions​

NameSummary
close[common]
open fun close()
process[common]
fun process(image: Tensor, options: ImageProcessOptions? = null, where: Placement? = null): Tensor
Preprocess decoded pixels: [H, W, C] (one image) or [N, H, W, C] (a batch) UInt8 channels-last.
[common]
fun process(bytes: ByteArray, options: ImageProcessOptions? = null, where: Placement? = null): Tensor
Preprocess an encoded image payload (PNG, JPEG, BMP, ...).
[common]
fun process(path: String, options: ImageProcessOptions? = null, where: Placement? = null): Tensor
Preprocess an image file; options override the configuration for this call, where the bound placement.
processBatch[common]
fun processBatch(images: List<ByteArray>, options: ImageProcessOptions? = null, where: Placement? = null): Tensor
Preprocess a batch of encoded images to [N, H, W, C]; every image must come out at one size.