This repository contains the Retfound model fine-tuned on the IDRID dataset and an API built with Flask to host and interact with the model.
-
Create a Python environment with conda:
conda create -n retfound python=3.7.5 -y conda activate retfound
-
Install dependencies:
git clone https://github.com/krishnaadithya/retfound_api.git cd retfound_api pip install -r requirements.txt
- Find the model
.pth
file here. - Download the file and place it in the
finetune_IDRID
folder in the root directory.
-
The API is built using Flask.
-
Host the model by running:
python retfound_api.py
-
For online tunneling, the current setup uses ngrok.
-
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.
-
Api file format: {'image': (image_path, image_data)}
-
Use the provided Python code to call the API:
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.