Package-level declarations

Types

Link copied to clipboard
Link copied to clipboard
interface InferenceEngine

The single seam between Faktel's model-agnostic pipelines and a native runtime (ONNX Runtime, LiteRT, NCNN...). Implement this to plug in a different backend; see the faktel-ort module for the reference implementation.

Link copied to clipboard

A loaded model, ready to run. Instances are not required to be thread-safe; use one per thread.

Link copied to clipboard
class Letterbox(val image: RgbImage, val scale: Double, val padX: Int, val padY: Int)

The result of letterbox: the padded square image and how to map its coordinates back to the source.

Link copied to clipboard
data class SessionOptions(val numThreads: Int = 2)

Tuning knobs shared by all backends; a backend may ignore what it cannot honour.

Link copied to clipboard
class Tensor(val shape: IntArray, val data: FloatArray)

A dense float32 tensor in row-major order. Shapes follow the model's native layout (Faktel models here use NCHW).

Functions

Link copied to clipboard
fun RgbImage.letterbox(size: Int, padValue: Int = 0): Letterbox

Resizes preserving aspect ratio to fit inside size x size, centring it on a canvas filled with padValue.

Link copied to clipboard
fun readBundleModel(name: String, extension: String, bundle: NSBundle = NSBundle.mainBundle): ByteArray

Reads a model bundled with the app, e.g. readBundleModel("face_detection_yunet_2023mar", "onnx").

Link copied to clipboard

Reads a model bundled in the app's assets/ directory.

Link copied to clipboard

Reads a model from the file system.

Link copied to clipboard
fun readModelResource(path: String, loader: ClassLoader = Thread.currentThread().contextClassLoader): ByteArray

Reads a model from the classpath (e.g. src/main/resources), or fails with a descriptive error.

Link copied to clipboard
fun tensorFromNSData(shape: List<Int>, data: NSData): Tensor

Builds a Tensor from float32 bytes.

Link copied to clipboard
fun NSData.toByteArray(): ByteArray

Copies the bytes into a new Kotlin ByteArray (e.g. a model or pixel buffer held by Swift as Data).

Link copied to clipboard
fun Tensor.toNSData(): NSData

Copies the tensor's float32 values (native byte order) into a new NSData.

fun ByteArray.toNSData(): NSData

Copies the bytes into a new NSData.

Link copied to clipboard
fun RgbImage.toTensor(order: ChannelOrder, mean: Float = 0.0f, scale: Float = 1.0f): Tensor

Packs the image into a [1, 3, height, width] float tensor: (value - mean) * scale per channel value.