File size: 3,024 Bytes
7dffa2c b671b9e 7dffa2c a28141d 7dffa2c a28141d 7dffa2c ffc458b 7dffa2c ffc458b 7dffa2c ffc458b 7dffa2c ffc458b 7dffa2c 203d916 7dffa2c 203d916 ffc458b 7dffa2c 203d916 7dffa2c 203d916 ffc458b 203d916 7dffa2c 203d916 7dffa2c 203d916 7dffa2c a28141d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | ---
license: cc-by-nc-4.0
datasets:
- aptos2019-blindness-detection
language:
- en
tags:
- diabetic-retinopathy
- resnet50
- deep-learning
- medical-imaging
- transformer
base_model:
- microsoft/resnet-50
pipeline_tag: image-classification
---
# Diabetic Retinopathy Detection Model  
## Overview
This model is a deep learning-based classifier designed to detect and classify diabetic retinopathy (DR) from retinal fundus images. It is built on the ResNet50 architecture and trained on the **APTOS 2019 Blindness Detection dataset**, which includes five DR severity classes:
- **0**: No DR
- **1**: Mild DR
- **2**: Moderate DR
- **3**: Severe DR
- **4**: Proliferative DR
The model aims to assist in early diagnosis and grading of diabetic retinopathy, reducing the workload for ophthalmologists and improving accessibility to screening.
## Usage
You can use this model by cloning the repository and using the pickled model by <i>torch.load()</i>.
### Dependencies Installation
Ensure you have the required dependencies installed:
```bash
pip install torch torchvision transformers opencv-python pandas
```
### Loading the Model
Clone the repository (with GIT LFS enabled)
```bash
git lfs install
git clone https://huggingface.co/sakshamkr1/ResNet50-APTOS-DR
```
Load the Model
```python
import torch
from PIL import Image
model = torch.load(model_path, map_location=torch.device('gpu'), weights_only=False) #Change torch.device to 'cpu' if using CPU
model.eval()
```
### Transformer Application
```python
from torchvision import transforms
transform = transforms.Compose([
transforms.Resize((224, 224)), # Resize image to match input size
transforms.ToTensor(), # Convert image to tensor
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) # Normalize using ImageNet stats
])
```
### Function to preprocess image and get predictions
```python
import numpy as np
def predict(image_path):
# Load and preprocess the input image
image = Image.open(image_path).convert('RGB') # Ensure RGB format
input_tensor = transform(image).unsqueeze(0).to(device) # Add batch dimension
# Perform inference
with torch.no_grad():
outputs = model(input_tensor) # Forward pass
probabilities = torch.nn.functional.softmax(outputs, dim=1) # Get class probabilities
return probabilities.cpu().numpy()[0] # Return probabilities as a NumPy array
# Test with an example image
image_path = "your_image_path" # Replace with your test image path
class_probs = predict(image_path)
# Print results
print(f"Class probabilities: {class_probs}")
predicted_class = np.argmax(class_probs) # Get the class with highest probability
print(f"Predicted class: {predicted_class}")
```
## License
This model is released under the **CC-BY-NC 4.0** license. |