Loading…
Loading…
A compact CNN (287,330 parameters) for benign-vs-malignant classification of 28×28 breast-ultrasound images, released with something most model uploads don't have: a script that re-derives every headline metric from the shipped weights and data, so the numbers below are checkable, not just claimed.
model.safetensors, the original PyTorch checkpoint (assets/sonocnn.pt), and ONNX (sonocnn.onnx, parity vs PyTorch measured at 9.5e-07 max logit difference).Research and benchmark use only. This is a 28×28 benchmark model trained on 546 images. It is not a medical device, it has never been evaluated on clinical data at native resolution, and it must not be used for diagnosis or screening.
| Metric | Value | Source |
|---|---|---|
| Accuracy | 0.8718 (136/156) | reproduced 2026-10-28 |
| ROC AUC | 0.8709 | reproduced 2026-10-28 |
| Balanced accuracy | 0.8145 | reproduced 2026-10-28 |
| Malignant recall (sensitivity) | 0.9386 (107/114) | reproduced 2026-10-28 |
| Benign recall (specificity) | 0.6905 (29/42) | reproduced 2026-10-28 |
| Malignant precision | 0.8917 (107/120) | reproduced 2026-10-28 |
| Benign precision | 0.8056 (29/36) | reproduced 2026-10-28 |
| Confusion matrix | [[29, 13], [7, 107]] (rows: true benign, true malignant) | reproduced 2026-10-28 |
| Majority-class baseline | 0.7308 | reproduced 2026-10-28 |
| Best validation accuracy | 0.8718 (68/78) | recorded at training time |
Read the weak row honestly: the model is much better at catching malignant cases (93.9%) than at clearing benign ones (69.1%) — 13 of 42 benign test images are flagged malignant. On a test set this small, the 95% confidence interval on accuracy is roughly ±5 points (≈0.81–0.92). The full reproduced record is in assets/evaluation_results.json; the training-time record is in assets/sonocnn_metrics.json; they agree exactly on every headline number.
pip install "git+https://github.com/habib-analyst/sonocnn.git"
from sonocnn import load_model, predict
model = load_model("model.safetensors") # or assets/sonocnn.pt
result = predict(model, "assets/demo_samples/benign.png")
# {'label': 'benign', 'confidence': 0.993,
# 'probabilities': {'benign': 0.993, 'malignant': 0.007}}
Preprocessing contract (identical to training): grayscale → resize to 28×28 → /255 → normalize with the BreastMNIST train-split mean/std (0.32758 / 0.20573). Labels: 0 = benign (normal/benign), 1 = malignant.
ONNX: sonocnn.onnx takes the same normalized (N, 1, 28, 28) float tensor and returns logits.
python examples/verify_metrics.py
This re-evaluates the shipped checkpoint on the bundled test split (assets/breastmnist.npz) and compares against the training-time metrics file. On 2026-10-28 it printed ALL HEADLINE METRICS REPRODUCED. Reproduction protocol matters: an earlier audit of this checkpoint briefly "failed" at 0.73 accuracy because the evaluator forgot the /255 step — the script exists so nobody has to take the card's word for anything.
python examples/predict_demo.py # bundled samples + optional ViewConsensus panel
python -m pytest -q # 8 tests: formats agree, metrics files agree, parity
The demo also composes SonoCNN with the sibling ViewConsensus library: on the first malignant test image, the single-view prediction is malignant at 70.2%, but the 8-view consensus panel reports 76.9% ±18.9% and returns an unsure — defer-to-human verdict. A confident single number is not the whole story; the spread is information.
BreastMNIST is part of MedMNIST v2 (Yang et al., MedMNIST v2 — A large-scale lightweight benchmark for 2D and 3D biomedical image classification, Scientific Data 2023), derived from the BUSI breast-ultrasound dataset (Al-Dhabyani et al., 2020). The dataset is licensed CC BY 4.0; assets/breastmnist.npz is redistributed here for metric reproduction, with attribution. The MIT license of this repository covers the code and the trained weights, not the dataset.
| File | Contents |
|---|---|
model.safetensors |
Release weights (safetensors) |
sonocnn.onnx / sonocnn.onnx.data |
ONNX export (logits) |
config.json |
Architecture + preprocessing config |
src/sonocnn/ |
model.py (architecture), infer.py (loading + prediction API) |
examples/predict_demo.py |
Inference demo incl. optional ViewConsensus panel |
examples/verify_metrics.py |
Full metric reproduction from the artifacts |
assets/sonocnn.pt |
Original training checkpoint (state dict + metrics) |
assets/sonocnn_metrics.json |
Training-time metrics record |
assets/evaluation_results.json |
Independently reproduced metrics (2026-10-28) |
assets/breastmnist.npz |
BreastMNIST splits (CC BY 4.0, see attribution) |
assets/demo_samples/ |
Two 256×256 ultrasound stills used by the demo |
MIT for code and weights (see LICENSE). Dataset under CC BY 4.0 as above.