v2026.11.2
All Bundles
Bundle

Convolutional neural networks on the CPU: layers with forward and backward passes, the Adam and SGD optimizers, an image dataset with train, validation and test splits and on-the-fly augmentation, and a training loop that records the metrics of every epoch. The layers are native (libobjk_ml, Eigen plus a small thread pool); this library holds the model API, the dataset and the trainer. Compile with -lib ml_cnn,ml,ml_lab,opencv,csv,json,cipher,gen_collect. Design, validation and measurements: docs/AI.md, "Convolutional networks (System.ML.Cnn)".

Augmentation

The random changes applied to a TRAINING image as it is loaded: a horizontal flip, a rotation by a small random angle (bilinear, zeros outside) and a brightness factor (the pixels are multiplied and clipped to 0 .. 1). Each fires with its own probability. Whether it fires, and its value, depend only on the seed and the image's position in the epoch, so a run repeats exactly.

Example

aug := Augmentation->New();
aug->SetFlip(0.5);                  # half the images are mirrored
aug->SetRotation(0.3, 10.0);        # 30% are turned by up to +-10 degrees
aug->SetBrightness(0.3, 0.8, 1.2);  # 30% are scaled by 0.8 .. 1.2

Operations

IsEnabled #

Is any augmentation switched on?

method : public : IsEnabled() ~ Bool

Return

TypeDescription
Booltrue if so

New # constructor

Creates a configuration that changes nothing.

New()

SetBrightness #

Brightness: the pixels are multiplied by a factor drawn uniformly from min_factor .. max_factor, then clipped to 0 .. 1.

method : public : SetBrightness(probability:Float, min_factor:Float, max_factor:Float) ~ Nil

Parameters

NameTypeDescription
probabilityFloatchance for each image, 0.0 to 1.0
min_factorFloatthe smallest factor, above 0
max_factorFloatthe largest factor

SetFlip #

Horizontal flip.

method : public : SetFlip(probability:Float) ~ Nil

Parameters

NameTypeDescription
probabilityFloatchance for each image, 0.0 to 1.0

SetRotation #

Rotation about the centre by an angle drawn uniformly from -max_degrees .. max_degrees.

method : public : SetRotation(probability:Float, max_degrees:Float) ~ Nil

Parameters

NameTypeDescription
probabilityFloatchance for each image, 0.0 to 1.0
max_degreesFloatthe largest angle in degrees

SetSeed #

The seed of the random draws.

method : public : SetSeed(seed:Int) ~ Nil

Parameters

NameTypeDescription
seedIntseed