Use ONNX-first model card structure
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677---library_name: pytorchtags:- image-classification- mnist- pytorch- onnx- multilayer-perceptrondatasets:- mnistmetrics:- accuracypipeline_tag: image-classification---# MNIST MLP ClassifierThis is a fully connected MNIST digit classifier trained as part of the[`dlab`](https://github.com/tsilva/dlab) deep-learning experimentation roadmap.The model is intentionally an MLP rather than a CNN. It is useful as a strongbaseline for studying optimization, regularization, augmentation, seed variance,and the ceiling of non-convolutional models on MNIST.## Results10-seed confirmation sweep:| metric | result || --- | ---: || validation accuracy | 99.3600% ± 0.0817 pp || validation loss | 0.15172 ± 0.00235 || test accuracy | 99.4470% ± 0.0195 pp || test loss | 0.14746 ± 0.00034 || test errors | 55.3 ± 1.95 / 10000 |## Architecture- Dataset: MNIST- Model: MLP- Hidden width: 1024- Hidden layers: 3- Activation: ReLU- Batch normalization: enabled- Dropout: 0.2- Optimizer: Adam- Learning rate: 0.001- Scheduler: OneCycleLR- Weight decay: 0.0001- Label smoothing: 0.02- Weight averaging: EMA- Train augmentation: random affine, 10 degrees, translate 0.05, scale 0.9-1.1## Files- `model.ckpt`: PyTorch Lightning checkpoint from the best run.- `model.onnx`: ONNX export of the EMA/current model state used for evaluation.- `config.yaml`: resolved Hydra training config.- `metrics.csv`: training metrics from the run.- `metadata.json`: compact metadata for inference and provenance.## PreprocessingInputs should be MNIST grayscale images converted to tensors and normalized with:```pythonmean = [0.1307]std = [0.3081]```The ONNX model expects float tensors shaped `[batch, 1, 28, 28]` under the inputname `images`, and returns class logits under the output name `logits`.## Provenance- W&B run: https://wandb.ai/tsilva/dlab/runs/gsuy1ifx- W&B sweep: https://wandb.ai/tsilva/dlab/sweeps/xa56lubb123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152---license: mitlibrary_name: onnxpipeline_tag: image-classificationtags:- image-classification- mnist- multilayer-perceptron- onnx- onnxruntime- pytorch- dlabdatasets:- mnistmetrics:- accuracy---# MNIST MLP ClassifierThis repository contains a validation-selected MNIST MLP digit classifier trained with [dlab](https://github.com/tsilva/dlab).## Architecture## Results10-seed confirmation sweep:| metric | value ||---|---:|| validation accuracy | 99.3600% ± 0.0817 pp || validation loss | 0.15172 ± 0.00235 || test accuracy | 99.4470% ± 0.0195 pp || test loss | 0.14746 ± 0.00034 || test errors | 55.3 ± 1.95 / 10000 |The ONNX model was exported from the best run checkpoint. Test metrics were produced after the recipe was selected and were logged in W&B sweep [`xa56lubb`](https://wandb.ai/tsilva/dlab/sweeps/xa56lubb).## Model Details- Dataset: MNIST- Architecture: MLP- Hidden width: `1024`- Hidden layers: `3`- Activation: ReLU- Batch normalization: enabled- Dropout: `0.2`- Optimizer: Adam- Learning rate: `0.001`- Weight decay: `0.0001`- Scheduler: OneCycleLR- Label smoothing: `0.02`- Weight averaging: EMA- Batch size: `512`- Training augmentation: random affine rotation/translation/scale- Source W&B run: [`gsuy1ifx`](https://wandb.ai/tsilva/dlab/runs/gsuy1ifx)- Source W&B sweep: [`xa56lubb`](https://wandb.ai/tsilva/dlab/sweeps/xa56lubb)## Input / OutputUse `model.onnx` for code-independent inference.- Input name: `images`- Input shape: `[batch, 1, 28, 28]`- Input dtype: `float32`- Output name: `logits`- Output shape: `[batch, 10]`Preprocessing:- Convert image to grayscale.- Resize to `28 x 28`.- Scale pixel values to `[0, 1]`.- Normalize with mean `0.1307` and standard deviation `0.3081`.- Arrange the tensor as channels-first `[batch, 1, 28, 28]`.## UsageInstall the runtime dependencies:```bashpip install huggingface_hub onnxruntime pillow numpy```Run inference with the ONNX model:```pythonimport numpy as npimport onnxruntime as ortfrom huggingface_hub import hf_hub_downloadfrom PIL import ImageLABELS = {0: "0",1: "1",2: "2",3: "3",4: "4",5: "5",6: "6",7: "7",8: "8",9: "9",}model_path = hf_hub_download(repo_id="tsilva/mnist-classifier-mlp",filename="model.onnx",)image = Image.open("example.png").convert("L").resize((28, 28))x = np.asarray(image, dtype=np.float32) / 255.0x = (x - 0.1307) / 0.3081x = x[None, None, :, :].astype(np.float32)session = ort.InferenceSession(model_path, providers=["CPUExecutionProvider"])logits = session.run(["logits"], {"images": x})[0]prediction = int(logits.argmax(axis=1)[0])print(prediction, LABELS[prediction])```## LabelsMNIST labels:| id | label ||---:|---|| 0 | 0 || 1 | 1 || 2 | 2 || 3 | 3 || 4 | 4 || 5 | 5 || 6 | 6 || 7 | 7 || 8 | 8 || 9 | 9 |## Files- `model.onnx`: ONNX export of the validation-selected checkpoint. Prefer this file for portable inference.- `model.ckpt`: PyTorch Lightning checkpoint for the same model. This is code-dependent and mainly useful for PyTorch-based inspection or continued experimentation.- `config.yaml`: resolved Hydra training config.- `metrics.csv`: training metrics from the uploaded checkpoint run.- `metadata.json`: compact metadata for inference and provenance.## LimitationsThis MLP does not use convolutional inductive bias. It performs strongly on MNIST, but remaining errors are mostly concentrated in ambiguous or unusually written digits.
README.md+115-40