programdemos/cnn-digits/batch.xtl

The digit reader over a batch: the first 1,000 MNIST test digits as one batch through the Conv library (the windows of every picture, one product for the batch, the pooling), then the dense layer; how many digits it reads right, the count the trainer's Rust forward pass gives from the same pixels. The batch run for a GPU (docs/gpu-asks.md); cnn-digits.xtl is the lesson, a picture at a time.

source · imports nn: libs/NN/src/NN.xtl; act: libs/Activations/src/Activations.xtl; cv: libs/Conv/src/Conv.xtl

The network, read from data/ (as cnn-digits.xtl reads it)

fb : Float

value · line 14
fb ← 8 10 r̲eshape n̲umbers ⎕N̲GET "data/filters.txt"
Used in: ᵘr̲ead

wb : Float

value · line 15
wb ← 1353 10 r̲eshape n̲umbers ⎕N̲GET "data/dense.txt"
Used in: ᵘr̲ead

The batch: the test digits, their pixels as whole percents, and their labels

X : Float

value · line 18
X ← (1000 28 28 r̲eshape n̲umbers ⎕N̲GET "data/test-digits.txt") ÷ 100.0
Used in: right

labels : Int

value · line 19
labels ← f̲loor n̲umbers ⎕N̲GET "data/test-labels.txt"
Used in: right

The reader

ᵘr̲ead : Float -> Int

function · line 25

The digit, 0 to 9, the network reads in each picture of a batch X: the filters over every window, ReLU, 2 x 2 pooling, the dense layer, the likeliest output. One function of arrays, the part a GPU takes.

ᵘr̲ead ← { X →
  (ⁿⁿa̲rgmax (((t̲ally X) c̲at 1352) r̲eshape ᶜᵛp̲ool ᵃᶜᵗr̲elu (9 t̲ake₂ fb, r̲avel -1 t̲ake₂ fb) ᶜᵛc̲onv X) ⁿⁿd̲ense wb) − 1
}
Used in: right

How many of the 1,000 it reads right, and that the Rust model counts the same