// Native RGB -> Float32 NCHW; immutable plan, reusable input storage.
import aner.video
import aner.vision
import aner.tensor
import aner.nn
import aner.ml

let source = video.synthetic(width: 160, height: 90, frames: 3)
let frame = video.frame_slot()
let plan = vision.preprocess(width: 32, height: 32, resize: "letterbox")
let input = vision.input_slot(plan)
while source.read_into(frame) == "ready" {
    plan.prepare_into(frame, input)
    print(tensor.rank(input.tensor()))
    print(tensor.dim(input.tensor(), 2))
    print(tensor.dim(input.tensor(), 3))
    print(tensor.cols(input.features()))
    print(input.sequence())
}
source.close()

// Synthetic one-row KNN round trip: explicit Float64 feature copy.
// Fitting and querying the same fixture demonstrates interoperability only;
// this is not held-out evaluation or evidence of recognition quality.
let features = input.features().astype("Float64")
let labels: Tensor = [[0.0]]
let neighbors = ml.fit_knn(features, labels, k: 1)
let predicted = neighbors.predict(features)
print(tensor.item(predicted))
