Downloads · 30 days
0
umairinayat/medical-models
medical-models is a image classification model from umairinayat. Use it when you need a label for an image. It is set up for pytorch. The card lists the license as mit.
This repository contains two complementary medical imaging AI model collections:
Downloads · 30 days
0
Access
Public
Updated Jun 25, 2026
Repo size
7.3 GB
Likes
0
Public
Click a slice to open those files.
.pt5 GB · 100%
From the Hugging Face model README
This repository contains two complementary medical imaging AI model collections:
A modality classification model that routes medical images to one of 7 imaging categories. Built on Microsoft's BiomedCLIP backbone, this router enables automatic sorting of medical images to the appropriate downstream model.
| Class | Modality |
|---|---|
| 0 | Endoscopy |
| 1 | Dermatology |
| 2 | X-Ray |
| 3 | Ultrasound |
| 4 | Mammography |
| 5 | Fundus / Retinography |
| 6 | Microscopy |
| Metric | Test Score |
|---|---|
| Accuracy | 100% |
| Macro F1 | 100% |
| Macro Precision | 100% |
| Macro Recall | 100% |
microsoft/BiomedCLIP-PubMedBERT_256-vit_base_patch16_224biomedclip_router_20260423_194004/
├── best_biomedclip_router.pt # Trained model weights (748MB)
├── metrics.json # Training metrics and history
├── train.log # Training logs
├── session_name.txt # Session identifier
└── unseen_holdout_300/ # Holdout test data info
A collection of specialized models for disease classification and segmentation across 8 medical imaging domains.
Task: Classify breast ultrasound images as benign, malignant, or normal
| Metric | Test Score |
|---|---|
| Accuracy | 92.31% |
| Macro F1 | 90.75% |
| Macro Precision | 89.79% |
| Macro Recall | 91.85% |
| Best Epoch | 23 |
Classes: benign, malignant, normal
Task: Segment lesions in breast ultrasound images
| Metric | Test Score |
|---|---|
| Dice | 83.80% |
| IoU | 76.17% |
| Best Epoch | 20 |
| Architecture | SMP UNet++ |
Files:
breast_ultrasound/
├── classification/
│ ├── best_classifier.pt
│ ├── metrics.json
│ └── plots/
└── segmentation/
├── best_segmentor.pt
├── metrics.json
└── plots/
Task: 4-class chest X-ray classification (COVID-19 Radiography Database)
| Metric | Test Score |
|---|---|
| Accuracy | 96.17% |
| Macro F1 | 96.08% |
| Macro Precision | 96.40% |
| Macro Recall | 95.79% |
| Best Epoch | 11 |
Classes: covid, lung_opacity, normal, viral_pneumonia
IMAGENET1K_V1, the CheXNet chest-X-ray backbone) + fresh 4-class head (replaces the previous 15-class BiomedCLIP multi-label model that scored ~21% exact-match accuracy)tawsifurrahman/covid19-radiography-database); also mirrored at dataset repo umairinayat/fyp-datasetImages per class (after dedup; total unique = 19,133):
| Class | Train | Val | Test | Total |
|---|---|---|---|---|
| covid | 2,225 | 477 | 477 | 3,179 |
| lung_opacity | 4,088 | 876 | 876 | 5,840 |
| normal | 6,152 | 1,318 | 1,319 | 8,789 |
| viral_pneumonia | 928 | 199 | 198 | 1,325 |
| Total | 13,393 | 2,870 | 2,870 | 19,133 |
Task: Binary lung-region segmentation (using the dataset's masks/)
| Metric | Test Score |
|---|---|
| Dice | 98.71% |
| IoU | 97.50% |
| Best Epoch | 15 |
| Architecture | SMP UNet (EfficientNet-B0 ImageNet encoder) |
Files:
chest_xray/
├── classification/
│ ├── best_classifier.pt
│ ├── metrics.json
│ ├── training_history.json
│ └── plots/
└── segmentation/
├── best_segmenter.pt
├── metrics.json
├── training_history.json
└── plots/
Task: Classify skin lesions as malignant or non-malignant (2-class)
| Metric | Test Score |
|---|---|
| Accuracy | 92.25% |
| Macro F1 | 90.47% |
| Macro Precision | 89.50% |
| Macro Recall | 91.63% |
| Best Epoch | 8 |
Classes: malignant, non_malignant
IMAGENET1K_V1) + 2-class head (replaces the previous BiomedCLIP model at 88.74%)surajghuwalewala/ham1000-segmentation-and-classification, 7->2 class) + fanconic/skin-cancer-malignant-vs-benignImages per class:
| Class | Train | Val | Test | Total |
|---|---|---|---|---|
| malignant | 2,559 | 307 | 585 | 3,451 |
| non_malignant | 7,108 | 1,182 | 1,571 | 9,861 |
| Total | 9,667 | 1,489 | 2,156 | 13,312 |
Task: Binary lesion segmentation (HAM10000 lesion masks)
| Metric | Test Score |
|---|---|
| Dice | 95.25% |
| IoU | 91.52% |
| Best Epoch | 18 |
| Architecture | SegFormer-B3 (transformer) |
nvidia/segformer-b3-finetuned-ade-512-512, ADE20K-pretrained) with a 1-label binary headsurajghuwalewala/ham1000-segmentation-and-classification), 10,015 image+mask pairslesion_id) so the same lesion never appears in both train and test -> train 6,987 / val 1,478 / test 1,550 (no leakage)Files:
dermatology/
├── classification/
│ ├── best_classifier.pt
│ ├── metrics.json
│ └── plots/
└── segmentation/
├── best_segmenter.pt
├── metrics.json
└── plots/
Task: Classify GI endoscopy images into 5 classes (healthy added vs. previous 4-class model)
| Metric | Test Score |
|---|---|
| Accuracy | 94.73% |
| Macro F1 | 80.35% |
| Macro Precision | 81.96% |
| Macro Recall | 79.66% |
| Best Epoch | 20 |
Classes: barretts, esophagitis, polyp, ulcerative_colitis, healthy
IMAGENET1K_V1) + fresh 5-class head (replaces the previous 4-class BiomedCLIP model)barretts<-{barretts,barretts-short-segment}, esophagitis<-{esophagitis-a,esophagitis-b-d}, polyp<-{polyps}, ulcerative_colitis<-{ulcerative-colitis-grade-*}, healthy<-{cecum,pylorus,z-line,retroflex-rectum,retroflex-stomach,ileum}barretts has only 94 images in all of HyperKvasir (66 train / 14 test), so it remains the hardest class and caps macro-F1; the other 4 classes score F1 0.84-0.99Images per class (after dedup; total unique = 6,695):
| Class | Train | Val | Test | Total |
|---|---|---|---|---|
| barretts | 66 | 14 | 14 | 94 |
| esophagitis | 463 | 100 | 99 | 662 |
| polyp | 713 | 152 | 153 | 1,018 |
| ulcerative_colitis | 587 | 126 | 126 | 839 |
| healthy | 2,857 | 612 | 613 | 4,082 |
| Total | 4,686 | 1,004 | 1,005 | 6,695 |
Task: Segment regions of interest in endoscopy images
| Metric | Test Score |
|---|---|
| Dice | 88.52% |
| IoU | 82.18% |
| Best Epoch | 38 |
| Architecture | SMP UNet++ |
Files:
endoscopy/
├── classification/
│ ├── best_classifier.pt
│ ├── metrics.json
│ └── plots/
└── segmentation/
├── best_segmentor.pt
├── metrics.json
└── plots/
Task: Classify mammogram patches as benign, malignant, or normal (3-class)
| Metric | Test Score |
|---|---|
| Accuracy | 99.63% |
| Macro F1 | 99.72% |
| Macro Precision | 99.71% |
| Macro Recall | 99.72% |
| Best Epoch | 12 |
Classes: benign, malignant, normal
IMAGENET1K_V2 pretrained weights) + fresh 3-class linear headImages per class (after dedup; total unique = 16,130):
| Class | Train | Val | Test | Total |
|---|---|---|---|---|
| benign | 4,505 | 965 | 966 | 6,436 |
| malignant | 5,428 | 1,163 | 1,163 | 7,754 |
| normal | 1,358 | 291 | 291 | 1,940 |
| Total | 11,291 | 2,419 | 2,420 | 16,130 |
Replaces the previous 2-class (BENIGN/MALIGNANT) BiomedCLIP mammography classifier (was 66% accuracy). The new model is a ResNet50 - load it with
torchvision.models.resnet50(see Usage below), not the BiomedCLIP loader.
Test confusion matrix (rows = true, cols = predicted benign, malignant, normal):
benign: [963, 3, 0]
malignant: [ 6, 1157, 0]
normal: [ 0, 0, 291]
Task: Binary mass segmentation in mammography (CBIS-DDSM)
| Metric | Test Score |
|---|---|
| Dice | 90.48% |
| IoU | 83.01% |
| Best Epoch | 13 |
| Architecture | SegFormer-B3 (transformer) |
nvidia/segformer-b3-finetuned-ade-512-512, ADE20K-pretrained), fine-tuned with a 1-label binary head — replaces the previous UNet++ (86.31% Dice)awsaf49/cbis-ddsm-breast-cancer-image-dataset); full mammogram + full-image ROI mask paired, square patch cropped around each lesion (2x margin) -> 512x512Files:
mammography/
├── classification/
│ ├── best_classifier.pt
│ ├── metrics.json
│ └── plots/
└── segmentation/
├── best_segmentor.pt
├── metrics.json
└── plots/
Task: Classify thyroid nodules by risk level
| Metric | Test Score |
|---|---|
| Accuracy | 88.57% |
| Macro F1 | 79.89% |
| Macro Precision | 76.79% |
| Macro Recall | 85.00% |
| Best Epoch | 8 |
Classes: low_risk, suspicious
Task: Segment thyroid nodules in ultrasound images
| Metric | Test Score |
|---|---|
| Dice | 83.43% |
| IoU | 73.64% |
| Best Epoch | 21 |
| Architecture | SMP UNet++ |
Files:
thyroid_ultrasound/
├── classification/
│ ├── best_classifier.pt
│ ├── metrics.json
│ └── plots/
└── segmentation/
├── best_segmentor.pt
├── metrics.json
└── plots/
| Domain | Accuracy | Macro F1 | Macro Precision | Macro Recall |
|---|---|---|---|---|
| BiomedCLIP Router | 100% | 100% | 100% | 100% |
| Mammography | 99.63% | 99.72% | 99.71% | 99.72% |
| Chest X-Ray | 96.17% | 96.08% | 96.40% | 95.79% |
| Endoscopy | 94.73% | 80.35% | 81.96% | 79.66% |
| Breast Ultrasound | 92.31% | 90.75% | 89.79% | 91.85% |
| Dermatology | 92.25% | 90.47% | 89.50% | 91.63% |
| Thyroid Ultrasound | 88.57% | 79.89% | 76.79% | 85.00% |
Mammography uses ResNet50, Endoscopy uses ConvNeXt-Small, and Chest X-Ray uses DenseNet121 (other disease classifiers use BiomedCLIP ViT-B/16).
| Domain | Dice | IoU | Architecture |
|---|---|---|---|
| Chest X-Ray | 98.71% | 97.50% | SMP UNet (EfficientNet-B0) |
| Dermatology | 95.25% | 91.52% | SegFormer-B3 |
| Mammography | 90.48% | 83.01% | SegFormer-B3 |
| Endoscopy | 88.52% | 82.18% | SMP UNet++ |
| Breast Ultrasound | 83.80% | 76.17% | SMP UNet++ |
| Thyroid Ultrasound | 83.43% | 73.64% | SMP UNet++ |
Counts = train / val / test images after de-duplication. "Unique total" = images actually used. Legacy BiomedCLIP / SMP models (Breast US, Thyroid US, Endoscopy seg, Fundus, Microscopy) were trained externally before this work; their per-class splits were not recorded and are marked N/R.
| Class | Train | Val | Test | Total |
|---|---|---|---|---|
| Endoscopy / Dermatology / X-Ray / Ultrasound / Mammography / Fundus / Microscopy (each) | 2,000 | 250 | 250 | 2,500 |
| Total (7 classes) | 14,000 | 1,750 | 1,750 | 17,500 |
| Class | Train | Val | Test | Total |
|---|---|---|---|---|
| benign | 4,505 | 965 | 966 | 6,436 |
| malignant | 5,428 | 1,163 | 1,163 | 7,754 |
| normal | 1,358 | 291 | 291 | 1,940 |
| Total | 11,291 | 2,419 | 2,420 | 16,130 |
| Split | Train | Val | Test | Total |
|---|---|---|---|---|
| image-mask patches | 979 | 172 | 341 | 1,492 |
| Class | Train | Val | Test | Total |
|---|---|---|---|---|
| covid | 2,225 | 477 | 477 | 3,179 |
| lung_opacity | 4,088 | 876 | 876 | 5,840 |
| normal | 6,152 | 1,318 | 1,319 | 8,789 |
| viral_pneumonia | 928 | 199 | 198 | 1,325 |
| Total | 13,393 | 2,870 | 2,870 | 19,133 |
| Split | Train | Val | Test | Total |
|---|---|---|---|---|
| image-mask pairs | 13,393 | 2,870 | 2,870 | 19,133 |
| Class | Train | Val | Test | Total |
|---|---|---|---|---|
| barretts | 66 | 14 | 14 | 94 |
| esophagitis | 463 | 100 | 99 | 662 |
| polyp | 713 | 152 | 153 | 1,018 |
| ulcerative_colitis | 587 | 126 | 126 | 839 |
| healthy | 2,857 | 612 | 613 | 4,082 |
| Total | 4,686 | 1,004 | 1,005 | 6,695 |
| Class | Train | Val | Test | Total |
|---|---|---|---|---|
| malignant | 2,559 | 307 | 585 | 3,451 |
| non_malignant | 7,108 | 1,182 | 1,571 | 9,861 |
| Total | 9,667 | 1,489 | 2,156 | 13,312 |
| Split | Train | Val | Test | Total |
|---|---|---|---|---|
| image-mask pairs | 6,987 | 1,478 | 1,550 | 10,015 |
| Model | Classes (from config) | Status |
|---|---|---|
| Breast Ultrasound (cls + seg) | benign / malignant / normal | BiomedCLIP / SMP UNet++ — N/R |
| Thyroid Ultrasound (cls + seg) | low_risk / suspicious | BiomedCLIP / SMP UNet++ — N/R |
| Endoscopy (segmentation) | polyp (binary) | SMP UNet++ — N/R |
| Fundus Retinography (cls) | no_retinal_disease / retinal_disease | BiomedCLIP — N/R; no segmentation |
| Microscopy (cls) | — | BiomedCLIP — N/R; no segmentation |
pip install torch torchvision huggingface_hub open_clip_torch segmentation-models-pytorch
# Download entire repository
hf download umairinayat/medical-models --local-dir ./medical-models
# Download specific components
hf download umairinayat/medical-models biomedclip_router_20260423_194004 --local-dir ./router
hf download umairinayat/medical-models disease_models --local-dir ./disease_models
import torch
import open_clip
from PIL import Image
# Load BiomedCLIP Router
model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms(
'hf-hub:microsoft/BiomedCLIP-PubMedBERT_256-vit_base_patch16_224'
)
tokenizer = open_clip.get_tokenizer(
'hf-hub:microsoft/BiomedCLIP-PubMedBERT_256-vit_base_patch16_224'
)
# Load trained router weights
checkpoint = torch.load('biomedclip_router_20260423_194004/best_biomedclip_router.pt', map_location='cpu')
model.load_state_dict(checkpoint['model_state_dict'])
# Inference
image = preprocess_val(Image.open('medical_image.png')).unsqueeze(0)
with torch.no_grad():
output = model(image)
predicted_class = output.argmax(dim=1).item()
class_names = ['Endoscopy', 'Dermatology', 'X-Ray', 'Ultrasound',
'Mammography', 'Fundus/Retinography', 'Microscopy']
print(f"Predicted modality: {class_names[predicted_class]}")
import torch
from PIL import Image
from torchvision import models, transforms
from huggingface_hub import hf_hub_download
# Load checkpoint
ckpt_path = hf_hub_download(
'umairinayat/medical-models',
'disease_models/mammography/classification/best_classifier.pt')
ckpt = torch.load(ckpt_path, map_location='cpu', weights_only=False)
class_names = ckpt['class_names'] # ['benign', 'malignant', 'normal']
# Build model
model = models.resnet50()
model.fc = torch.nn.Linear(model.fc.in_features, len(class_names))
model.load_state_dict(ckpt['model_state'])
model.eval()
# Preprocess (224x224, grayscale -> RGB, ImageNet stats)
tfm = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(ckpt['normalization_mean'], ckpt['normalization_std']),
])
img = Image.open('mammogram.png').convert('RGB')
x = tfm(img).unsqueeze(0)
with torch.no_grad():
probs = torch.softmax(model(x), dim=1)[0]
print({c: round(float(p), 4) for c, p in zip(class_names, probs)})
These models are designed for:
All classification models were trained with:
hf-hub:microsoft/BiomedCLIP-PubMedBERT_256-vit_base_patch16_224Exception - Mammography: trained with
torchvision.resnet50(IMAGENET1K_V2), a fresh 3-class head, AdamW + OneCycleLR, class-weighted CrossEntropy, on a deduplicated INbreast+MIAS+DDSM (CLAHE) split with leakage-free train/val/test separation. Seedisease_models/mammography/classification/metrics.json.
All segmentation models were trained with:
If you use these models, please cite:
@misc{medical-models-2026,
author = {Umair Inayat},
title = {Medical Imaging Models: BiomedCLIP Router and Disease-Specific Classifiers},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/umairinayat/medical-models}
}
MIT License
For questions or issues, please open an issue on the Hugging Face repository.
Models trained and pushed during the current update cycle (each under disease_models/<disease>/{classification,segmentation}/, with weights + metrics.json + training_history.json + plots).
| # | Disease / task | Backbone | Result | Status |
|---|---|---|---|---|
| 1 | Mammography — Classification (3-class) | ResNet50 | 99.63% accuracy | pushed |
| 2 | Mammography — Segmentation (mass) | SegFormer-B3 | 90.48% Dice | pushed |
| 3 | Chest X-Ray — Classification (4-class) | DenseNet121 | 96.17% accuracy | pushed |
| 4 | Chest X-Ray — Segmentation (lung) | UNet (EfficientNet-B0) | 98.71% Dice | pushed |
| 5 | Dermatology — Classification (2-class) | ConvNeXt-Small | 92.25% accuracy | pushed |
| 6 | Dermatology — Segmentation (lesion) | SegFormer-B3 | 95.25% Dice | pushed |
| 7 | Endoscopy — Classification (5-class, healthy added) | ConvNeXt-Small | 94.73% accuracy | pushed |
Dataset also pushed: umairinayat/fyp-dataset — COVID-19 Radiography (21,165 images + masks).
Trained but not pushed (came out below the existing repo models, so the originals were kept):
Untouched (original/legacy models retained): BiomedCLIP Router, Breast Ultrasound, Thyroid Ultrasound, Fundus Retinography, Microscopy, and Endoscopy segmentation.