https://github.com/krishnaadithya/retfound_api
Api to host Retfound
https://github.com/krishnaadithya/retfound_api
diabetic-retinopathy diabetic-retinopathy-detection dr fundus idrid retfound
Last synced: 2 months ago
JSON representation
Api to host Retfound
- Host: GitHub
- URL: https://github.com/krishnaadithya/retfound_api
- Owner: krishnaadithya
- License: other
- Created: 2023-12-13T23:59:27.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-14T01:28:10.000Z (almost 2 years ago)
- Last Synced: 2025-03-28T11:16:59.259Z (6 months ago)
- Topics: diabetic-retinopathy, diabetic-retinopathy-detection, dr, fundus, idrid, retfound
- Language: Jupyter Notebook
- Homepage:
- Size: 384 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Retfound Model API
This repository contains the Retfound model fine-tuned on the [IDRID dataset](https://www.kaggle.com/datasets/mariaherrerot/idrid-dataset/) and an API built with Flask to host and interact with the model.
## Install Environment
1. Create a Python environment with conda:
```bash
conda create -n retfound python=3.7.5 -y
conda activate retfound
```2. Install dependencies:
```bash
git clone https://github.com/krishnaadithya/retfound_api.git
cd retfound_api
pip install -r requirements.txt
```## Steps to Use the API
### 1. Download Model File
- Find the model `.pth` file [here](https://drive.google.com/file/d/1uKW5ZjKdKar3ZGAXu6u7I1a8B5s-uxH8/view?usp=sharing).
- Download the file and place it in the `finetune_IDRID` folder in the root directory.### 2. Running the API
- The API is built using Flask.
- Host the model by running:```bash
python retfound_api.py
```### 3. Accessing the API
- For online tunneling, the current setup uses [ngrok](https://ngrok.com/).
- Currently, the model is hosted locally, and you can use the following endpoint to push your image: [https://623c-2001-8f8-166b-2a54-b5d7-fefa-f504-a420.ngrok-free.app/predict](https://623c-2001-8f8-166b-2a54-b5d7-fefa-f504-a420.ngrok-free.app/predict).
- Api file format: {'image': (image_path, image_data)}
- Use the provided Python code to call the API:```python
import requests
from PIL import Image
import io
import time
# Replace 'your_image.jpg' with the path to your image file
image_path = 'your_image.jpg'
# Open the image file
with open(image_path, 'rb') as f:
image_data = f.read()
# Create a dictionary containing the image file
files = {'image': (image_path, image_data)}
# Make a POST request to the API endpoint
url = "https://623c-2001-8f8-166b-2a54-b5d7-fefa-f504-a420.ngrok-free.app/predict" # Replace this link with your endpoint
response = requests.post(url, files=files)
# Check if the request was successful (status code 200)
if response.status_code == 200:
result = response.json()
print(f'Predicted category: {result["predictions"]}')
else:
print(f'Error: {response.text}')
```Please replace `your_image.jpg` with the path to your image file before running the code.