JobayerFaisal/Retinal_Disease_Detection
0
๐ฉบ 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
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
cd YOUR_SPACE_NAME2๏ธโฃ Create Virtual Environment (Recommended)
python -m venv venv
source venv/bin/activate # Mac/Linux
venv\Scripts\activate # Windows3๏ธโฃ Install Dependencies
pip install -r requirements.txtโถ๏ธ Run Locally
streamlit run app.pyApp will open at:
http://localhost:8501๐ฆ Deployment (Hugging Face Spaces)
- Create a new Space
- 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
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:
torch.save(model.state_dict(), "model.pth")โ ๏ธ Important Notes
- The model must be loaded with
weights=Nonefor ResNet50 during deployment. - Ensure architecture in
model.pyexactly 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
