This repository contains a validation-selected MNIST RNN digit classifier trained with
dlab.
The ONNX model was exported from the validation-selected checkpoint. Test metrics were produced after the recipe was selected and were logged in W&B test-audit run
vdt5duxq.
1import numpy as np
2import onnxruntime as ort
3from huggingface_hub import hf_hub_download
4from PIL import Image
5
6LABELS = {
7 0: "0",
8 1: "1",
9 2: "2",
10 3: "3",
11 4: "4",
12 5: "5",
13 6: "6",
14 7: "7",
15 8: "8",
16 9: "9",
17}
18
19model_path = hf_hub_download(
20 repo_id="tsilva/mnist-classifier-rnn",
21 filename="model.onnx",
22)
23
24image = Image.open("example.png").convert("L").resize((28, 28))
25x = np.asarray(image, dtype=np.float32) / 255.0
26x = (x - 0.1307) / 0.3081
27x = x[None, None, :, :].astype(np.float32)
28
29session = ort.InferenceSession(model_path, providers=["CPUExecutionProvider"])
30logits = session.run(["logits"], {"images": x})[0]
31prediction = int(logits.argmax(axis=1)[0])
32
33print(prediction, LABELS[prediction])
This RNN model treats each MNIST image as a short sequence rather than using convolutional inductive bias. It is intended for normalized 28 x 28 grayscale MNIST-style images; remaining errors are expected to concentrate in ambiguous handwritten digits and distribution shifts outside that input format.