CoolFace
Apppublic

JobayerFaisal/Retinal_Disease_Detection

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

๐Ÿฉบ OCT Retinal Disease Classification using ResNet50 + LSTM

๐Ÿ“Œ Overview

This project implements a deep learning model for Optical Coherence Tomography (OCT) retinal disease classification using a hybrid architecture:

  • โ€”ResNet50 (feature extraction)
  • โ€”LSTM (spatial sequence modeling)
  • โ€”Fully Connected layer (multi-class classification)

The model classifies OCT images into the following categories:

  • โ€”AMD
  • โ€”CNV
  • โ€”CSR
  • โ€”DME
  • โ€”DR
  • โ€”DRUSEN
  • โ€”MH
  • โ€”NORMAL

The application is deployed using Streamlit and hosted on Hugging Face Spaces.


๐Ÿง  Model Architecture

Backbone

  • โ€”Pretrained ResNet50 (final classification layers removed)
  • โ€”Extracts 2048-dimensional feature maps

Sequence Model

  • โ€”LSTM layer
  • โ€”Input size: 2048
  • โ€”Hidden size: 256
  • โ€”Number of layers: 1

Output Layer

  • โ€”Fully connected layer
  • โ€”Output classes: 8

Architecture Flow:

Input Image (224x224)
        โ†“
ResNet50 (Feature Extractor)
        โ†“
Reshape to sequence
        โ†“
LSTM
        โ†“
Fully Connected Layer
        โ†“
Softmax Prediction

๐Ÿ“‚ Project Structure

OCT-Classification-App/
โ”‚
โ”œโ”€โ”€ app.py              # Streamlit application
โ”œโ”€โ”€ model.py            # Model architecture definition
โ”œโ”€โ”€ model.pth           # Trained model weights
โ”œโ”€โ”€ requirements.txt    # Dependencies
โ””โ”€โ”€ README.md           # Project documentation

โš™๏ธ Installation (Local Setup)

1๏ธโƒฃ Clone Repository

bash
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
cd YOUR_SPACE_NAME

2๏ธโƒฃ Create Virtual Environment (Recommended)

bash
python -m venv venv
source venv/bin/activate   # Mac/Linux
venv\Scripts\activate      # Windows

3๏ธโƒฃ Install Dependencies

bash
pip install -r requirements.txt

โ–ถ๏ธ Run Locally

bash
streamlit run app.py

App will open at:

http://localhost:8501

๐Ÿ“ฆ Deployment (Hugging Face Spaces)

  1. 1.Create a new Space
  2. 2.Choose:
  • โ€”SDK: Streamlit
  • โ€”Hardware: CPU Basic
  • โ€”Upload:
  • โ€”app.py
  • โ€”model.py
  • โ€”model.pth
  • โ€”requirements.txt
  • โ€”Commit & Deploy

No additional configuration required.


๐Ÿ”„ Preprocessing Pipeline

During inference, each image undergoes:

  • โ€”Resize to 224ร—224
  • โ€”Convert to Tensor
  • โ€”ImageNet normalization
python
transforms.Normalize(
    mean=[0.485, 0.456, 0.406],
    std=[0.229, 0.224, 0.225]
)

This ensures consistency with ResNet50 expectations.


๐Ÿ–ฅ๏ธ Requirements

streamlit
torch
torchvision
pillow
numpy

๐Ÿ“Š Model Training Details

  • โ€”Loss Function: CrossEntropyLoss
  • โ€”Optimizer: Adam
  • โ€”Input size: 224ร—224 RGB images
  • โ€”Training Framework: PyTorch

Model weights are saved using:

python
torch.save(model.state_dict(), "model.pth")

โš ๏ธ Important Notes

  • โ€”The model must be loaded with weights=None for ResNet50 during deployment.
  • โ€”Ensure architecture in model.py exactly matches training architecture.
  • โ€”CPU inference supported.

๐Ÿ“ˆ Future Improvements

  • โ€”Add confidence scores
  • โ€”Add Grad-CAM visualization
  • โ€”Add model performance metrics display
  • โ€”Convert to TorchScript for faster inference
  • โ€”Add API endpoint (FastAPI version)

๐Ÿ‘ค Author

Jobayer Faisal Fahim Machine Learning & AI Researcher