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)".

ImageSubset

A list of images of an ImageDataset, in a fixed order, that CnnTrainer batches over. Only a subset made for training augments; Augmentation is applied on the fly while a batch is staged and never changes the stored images.

Operations

Begin #

Starts decoding the images at positions order[start .. start + count) of this subset in the background (see ImageDataset->SetThreads) and returns at once.

method : public : Begin(order:Int[], start:Int, count:Int) ~ PendingImages

Parameters

NameTypeDescription
orderIntpositions in this subset
startIntfirst entry of order
countInthow many

Return

TypeDescription
PendingImagesthe pending images, Nil if the range or an index is invalid

Count #

The number of images.

method : public : Count() ~ Int

Return

TypeDescription
Intcount

CountPositives #

Counts the images of class 1.

method : public : CountPositives() ~ Int

Return

TypeDescription
Intcount

GetAugmentation #

Gets the augmentation.

method : public : GetAugmentation() ~ Augmentation

Return

TypeDescription
Augmentationthe configuration

GetError #

Why the last Stage call refused.

method : public : GetError() ~ String

Return

TypeDescription
Stringthe reason

GetIndex #

The index in the dataset of the image at a position.

method : public : GetIndex(position:Int) ~ Int

Parameters

NameTypeDescription
positionIntposition in this subset

Return

TypeDescription
Intdataset index, -1 if out of range

GetLabel #

The class label of the image at a position.

method : public : GetLabel(position:Int) ~ Int

Parameters

NameTypeDescription
positionIntposition in this subset

Return

TypeDescription
Int0 or 1, -1 if out of range

IsAugmented #

Is this subset augmented?

method : public : IsAugmented() ~ Bool

Return

TypeDescription
Booltrue for a training subset

SetAugmentation #

Sets the augmentation used when this subset is a training subset (it is ignored for subsets made with augment = false).

method : public : SetAugmentation(aug:Augmentation) ~ Nil

Parameters

NameTypeDescription
augAugmentationthe configuration

Stage #

Stages the image at a position into a slot of the model's batch.

method : public : Stage(model:CnnModel, position:Int, slot:Int, total:Int, key:Int) ~ Bool

Parameters

NameTypeDescription
modelCnnModelthe model
positionIntposition in this subset
slotIntindex in the batch
totalIntimages in the batch
keyIntvaries the random draws, e.g. epoch * count + position

Return

TypeDescription
Booltrue if staged

StageFrom #

Stages image j of a pending batch (made by Begin) into slot j of the model's batch: the same as Stage for the position it was begun with.

method : public : StageFrom(model:CnnModel, pending:PendingImages, j:Int, total:Int, key:Int) ~ Bool

Parameters

NameTypeDescription
modelCnnModelthe model
pendingPendingImagesthe pending batch
jIntposition in the pending batch, also the slot
totalIntimages in the batch
keyIntvaries the random draws, e.g. epoch * count + position

Return

TypeDescription
Booltrue if staged