--- title: RBC Morphology Classifier emoji: 🔬 colorFrom: red colorTo: pink sdk: gradio sdk_version: 3.50.2 app_file: app.py pinned: false license: apache-2.0 --- # 🔬 RBC Morphology Classifier AI-powered Red Blood Cell analysis for anemia detection using deep learning. ## 🎯 Overview This Hugging Face Space hosts a trained **EfficientNet-B0** model that classifies red blood cell (RBC) microscopy images as **healthy** or **anemic**. The model was trained on the AneRBC-II dataset containing 12,000 labeled RBC images. ## 📊 Model Performance - **Architecture:** EfficientNet-B0 (transfer learning) - **Training Dataset:** AneRBC-II (12,000 images) - 6,000 healthy RBC images - 6,000 anemic RBC images - **Validation Accuracy:** 95.83% - **Test Accuracy:** ~95% - **Model Size:** ~16 MB - **Input Size:** 224×224 RGB images - **Classes:** 2 (healthy, anemic) ## 🚀 Usage ### Web Interface 1. Upload an RBC microscopy image (JPG, PNG, or BMP) 2. Click "Classify RBC" 3. View results with confidence scores and probabilities ### API Access **Python (Gradio Client):** ```python from gradio_client import Client client = Client("YOUR_USERNAME/rbc-morphology-classifier") result = client.predict("path/to/rbc_image.jpg", api_name="/predict") print(result) ``` **Python (requests):** ```python import requests import base64 # Read and encode image with open("rbc_image.jpg", "rb") as f: image_b64 = base64.b64encode(f.read()).decode() # Call API response = requests.post( "https://YOUR_USERNAME-rbc-morphology-classifier.hf.space/api/predict", json={"data": [image_b64]} ) print(response.json()) ``` **cURL:** ```bash curl -X POST \ https://YOUR_USERNAME-rbc-morphology-classifier.hf.space/api/predict \ -H "Content-Type: application/json" \ -d '{"data": ["base64_encoded_image"]}' ``` ## 📈 Example Output ```json { "prediction": "anemic", "confidence": 0.9421, "probabilities": { "healthy": 0.0579, "anemic": 0.9421 }, "model": "EfficientNet-B0", "dataset": "AneRBC-II (12,000 images)", "validation_accuracy": "95.83%" } ``` ## 🔬 Training Details ### Dataset: AneRBC-II The model was trained on the **AneRBC-II** dataset, a benchmark dataset for computer-aided anemia diagnosis: - **Source:** Mendeley Data - **Total Images:** 12,000 (306×320 pixels each) - **Classes:** Healthy (6,000) and Anemic (6,000) - **Includes:** Original images, segmentation masks, CBC reports, morphology reports - **License:** CC BY 4.0 ### Training Configuration - **Framework:** PyTorch 2.1.0 - **Model:** EfficientNet-B0 (pretrained on ImageNet) - **Optimizer:** AdamW (lr=1e-4, weight_decay=1e-4) - **Scheduler:** CosineAnnealingLR (T_max=20) - **Loss:** CrossEntropyLoss - **Batch Size:** 32 - **Epochs:** 20 - **Data Split:** 70% train / 15% val / 15% test - **Augmentation:** Random flips, rotation (20°), color jitter ### Data Augmentation Training images were augmented with: - Random horizontal and vertical flips - Random rotation (±20°) - Color jitter (brightness, contrast) - Resize to 224×224 - Normalization (ImageNet statistics) ## 📚 Citation ### Dataset Citation If you use this model or the AneRBC dataset in your research, please cite: ```bibtex @article{shahzad2024anerbc, title={AneRBC dataset: a benchmark dataset for computer-aided anemia diagnosis using RBC images}, author={Shahzad, Muhammad and Shirazi, Syed Hamad and Yaqoob, Muhammad and Khan, Zakir and Rasheed, Assad and Sheikh, Israr Ahmed and Hayat, Asad and Zhou, Huiyu}, journal={Database}, volume={2024}, pages={baae120}, year={2024}, publisher={Oxford University Press}, doi={10.1093/database/baae120}, url={https://doi.org/10.1093/database/baae120} } ``` **Dataset Link:** https://data.mendeley.com/datasets/hms3sjzt7f/1 ### Model Citation ```bibtex @software{rbc_morphology_classifier, title={RBC Morphology Classifier: EfficientNet-B0 for Anemia Detection}, author={Your Name}, year={2024}, url={https://huggingface.co/spaces/YOUR_USERNAME/rbc-morphology-classifier} } ``` ## ⚠️ Disclaimer **This model is intended for research and educational purposes only.** - **NOT FOR CLINICAL USE:** This tool should not be used as the sole basis for medical diagnosis or treatment decisions. - **Consult Professionals:** Always seek the advice of qualified healthcare professionals for medical concerns. - **Accuracy Limitations:** While the model achieves ~95% accuracy on test data, real-world performance may vary. - **Bias:** Model performance depends on image quality, staining techniques, and population characteristics. ## 🔗 Related Links - **AneRBC Dataset (Mendeley):** https://data.mendeley.com/datasets/hms3sjzt7f/1 - **Publication (Database Journal):** https://doi.org/10.1093/database/baae120 - **EfficientNet Paper:** https://arxiv.org/abs/1905.11946 - **Timm Library:** https://github.com/huggingface/pytorch-image-models ## 📄 License - **Model:** Apache 2.0 - **Dataset (AneRBC):** CC BY 4.0 - **Code:** Apache 2.0 ## 🤝 Acknowledgments - **Dataset Authors:** Muhammad Shahzad, Syed Hamad Shirazi, Muhammad Yaqoob, et al. - **AneRBC Team:** Shaukat Khanum Memorial Cancer Hospital and Research Centre - **Framework:** PyTorch, Timm, Gradio, Hugging Face Spaces ## 📧 Contact For questions, issues, or collaborations, please open an issue in the discussion tab or contact the Space owner. --- **Built with ❤️ for medical AI research**