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
- Count
- CountPositives
- GetAugmentation
- GetError
- GetIndex
- GetLabel
- IsAugmented
- SetAugmentation
- Stage
- StageFrom
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) ~ PendingImagesParameters
| Name | Type | Description |
|---|---|---|
| order | Int | positions in this subset |
| start | Int | first entry of order |
| count | Int | how many |
Return
| Type | Description |
|---|---|
| PendingImages | the pending images, Nil if the range or an index is invalid |
CountPositives #
Counts the images of class 1.
method : public : CountPositives() ~ IntReturn
| Type | Description |
|---|---|
| Int | count |
GetAugmentation #
Gets the augmentation.
method : public : GetAugmentation() ~ AugmentationReturn
| Type | Description |
|---|---|
| Augmentation | the configuration |
GetError #
Why the last Stage call refused.
method : public : GetError() ~ StringReturn
| Type | Description |
|---|---|
| String | the reason |
GetIndex #
The index in the dataset of the image at a position.
method : public : GetIndex(position:Int) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| position | Int | position in this subset |
Return
| Type | Description |
|---|---|
| Int | dataset index, -1 if out of range |
GetLabel #
The class label of the image at a position.
method : public : GetLabel(position:Int) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| position | Int | position in this subset |
Return
| Type | Description |
|---|---|
| Int | 0 or 1, -1 if out of range |
IsAugmented #
Is this subset augmented?
method : public : IsAugmented() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true 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) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| aug | Augmentation | the 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) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| model | CnnModel | the model |
| position | Int | position in this subset |
| slot | Int | index in the batch |
| total | Int | images in the batch |
| key | Int | varies the random draws, e.g. epoch * count + position |
Return
| Type | Description |
|---|---|
| Bool | true 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) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| model | CnnModel | the model |
| pending | PendingImages | the pending batch |
| j | Int | position in the pending batch, also the slot |
| total | Int | images in the batch |
| key | Int | varies the random draws, e.g. epoch * count + position |
Return
| Type | Description |
|---|---|
| Bool | true if staged |