chest-xray-classifier

chest-xray-classifier - 3-class pneumonia classification

A 3-class chest X-ray classifier that distinguishes bacterial pneumonia, normal, and viral pneumonia on pediatric frontal chest radiographs. The main model is a ConvNeXt-V2-Tiny fine-tuned with the transformers library; a DINOv2 ViT-S linear probe serves as the baseline.

Medical disclaimer: this model is provided for research and educational purposes only. It is not a medical device and must not be used for clinical diagnosis or treatment decisions.

Metrics

Evaluated on the held-out test split (624 radiographs: 242 bacterial / 234 normal / 148 viral). All values are reported as percentages.

Model Accuracy Macro F1 Macro AUROC (OvR)
ConvNeXt-V2-Tiny (main) 91.3% 90.3% 97.5%
DINOv2 ViT-S linear probe (baseline) 85.6% 84.2% 94.2%

Per-class results (main model)

Class Precision Recall F1 Support
bacterial_pneumonia 89.1% 98.3% 93.5% 242
normal 99.5% 89.7% 94.4% 234
viral_pneumonia 83.6% 82.4% 83.0% 148
Macro avg 90.7% 90.2% 90.3% 624
Weighted avg 91.7% 91.3% 91.3% 624

Visualizations

All charts below are generated by scripts/make_plots.py, which runs this exact model over the full test split. The computed accuracy / macro-F1 / macro-AUROC are cross-checked against the committed evaluation report before any chart is rendered.

Confusion matrix

Confusion matrix

Counts and row-normalized rates on the 624-image test split. Bacterial pneumonia and normal are recognized strongly; the main source of error is viral pneumonia being predicted as bacterial pneumonia, which is the clinically hardest distinction in this dataset.

ROC curves (one-vs-rest)

ROC curves

One-vs-rest ROC curves with per-class AUROC. The normal class separates near-perfectly, while viral pneumonia is the most challenging, consistent with the confusion matrix.

Sample predictions

Sample predictions

Representative correctly-classified test radiographs (two per class) with predicted class and softmax confidence.

Usage

import torch
from PIL import Image
from transformers import AutoImageProcessor, AutoModelForImageClassification

processor = AutoImageProcessor.from_pretrained("kiselyovd/chest-xray-classifier")
model = AutoModelForImageClassification.from_pretrained("kiselyovd/chest-xray-classifier")
model.eval()

image = Image.open("your_radiograph.png").convert("RGB")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
    logits = model(**inputs).logits

probs = torch.softmax(logits, dim=-1)[0]
pred_id = int(probs.argmax())
print(model.config.id2label[pred_id], float(probs[pred_id]))

Class index order (model id2label): 0 -> bacterial_pneumonia, 1 -> normal, 2 -> viral_pneumonia.

Training data

Trained on the Chest X-Ray Images (Pneumonia) dataset of pediatric frontal chest radiographs. The original two-class layout (NORMAL / PNEUMONIA) is split into three classes by separating the PNEUMONIA images into bacterial and viral cases, producing the bacterial_pneumonia / normal / viral_pneumonia target space.

Intended use and limitations

Research and educational use only. This model is not a medical device, has not been clinically validated, and must not be used for diagnosis or any clinical decision-making. It was trained on a single pediatric dataset and may not generalize to adult radiographs, other imaging equipment, or different acquisition protocols. Users are responsible for evaluating fitness for their use case, including fairness, safety, and compliance with applicable regulations.

Source code

GitHub Repository

License

MIT.

Downloads last month
159
Safetensors
Model size
27.9M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for kiselyovd/chest-xray-classifier

Finetuned
(7)
this model

Dataset used to train kiselyovd/chest-xray-classifier

Evaluation results