Lucario-K17/Chestxray_or_not_classification
13
Lucario-K17/Chestxrayornot_classification
A lightweight deep learning model to classify whether an input image is a Chest X-ray or not. Achieves 100% accuracy on validation and test sets using a MobileNetV2 backbone.
Overview
This model distinguishes between chest X-ray images and non-X-ray/general images. It is ideal for use as a pre-check in medical pipelines to verify that the uploaded image is indeed a valid X-ray before performing diagnosis.
- ✅ Binary classification: Chest X-ray ✅ or Not ❌
- ✅ Fast & lightweight (MobileNetV2)
- ✅ Trained on NIH ChestX-ray14 + general images
- ✅ 100% accuracy in test/validation data
Setup Instructions
Install required libraries:
pip install torch torchvision pillow huggingface_hubModel Loading & Inference Code
import torch
from torchvision.models import mobilenet_v2
from torchvision import transforms
from PIL import Image
from huggingface_hub import hf_hub_download
# Load pretrained model
Check_model = mobilenet_v2(pretrained=False)
Check_model.classifier[1] = torch.nn.Linear(Check_model.last_channel, 1)
Check_model.load_state_dict(
torch.load(hf_hub_download("Lucario-K17/ChestXrayOrNot", "model.pth"), map_location="cpu")
)
Check_model.eval()
# Prediction function
def is_chest_xray(img: Image.Image) -> bool:
preprocess = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.5], [0.5])
])
x = preprocess(img).unsqueeze(0)
with torch.no_grad():
output = torch.sigmoid(Check_model(x)).item()
return output > 0.5Usage Example
from PIL import Image
img = Image.open("sample_image.jpg")
result = is_chest_xray(img)
print("Is Chest X-ray:", " Yes" if result else " No")Training Progress
The model reaches ~98% accuracy in just 3 epochs and converges to 100% accuracy by the final evaluation.
Results
- Dataset: NIH ChestX-ray14 and general images
- Framework: PyTorch
- Architecture: MobileNetV2
- Training Time: ~3 epochs
Citation (MIT-GA License Style)
If you use this model, you must cite or link back to the model page:
@misc{lucario2025chestxraycheck,
title = {ChestXray or Not Classifier},
author = {Kishore Murugan},
year = {2025},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/Lucario-K17/Chestxray_or_not_classification}},
note = {Licensed under MIT-GA; citation or model link required for use}
}MIT-GA (MIT-Give Attribution): This license permits unrestricted use, modification, and distribution of the model as long as attribution is provided by linking to the original model or citing it in your work.
License
MIT-GA License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. Attribution must be given to the
original model author by linking to the Hugging Face model card or citing it.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.Hugging Face Model Link
👉 Lucario-K17/Chestxray_or_not_classification
🙏 Acknowledgements
- NIH ChestX-ray14 Dataset: https://nihcc.app.box.com/v/ChestXray-NIHCC
- Hugging Face for model hosting
- PyTorch for model training
