Spaces:
Sleeping
Sleeping
File size: 2,204 Bytes
f39bf0e ab26eab f39bf0e |
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 |
from fastai.vision.all import *
import gradio as gr
from pathlib import Path
import pandas as pd
def get_x(row):
# All files are assumed to be '.jpg', so we directly return the path with '.jpg' extension
return path_image_combined / f"{row['file_name']}.jpg"
def get_y(row):
return row['Buried ODD']
# Load the models into a dictionary
models = {
'Ultrasound': load_learner('ODDUltrasound.pkl'),
'OCT': load_learner('ODDOCT.pkl'),
'Fundus': load_learner('ODDfundus.pkl'),
'Fluorescence': load_learner('ODDfluorescence.pkl')
}
modality_keys = ['Ultrasound', 'OCT', 'Fundus', 'Fluorescence']
def classify_images(img_ultrasound, img_oct, img_fundus, img_fluorescence):
imgs = [img_ultrasound, img_oct, img_fundus, img_fluorescence]
predictions = []
detailed_predictions = [] # To store detailed predictions for each modality
# Convert images to PILImage and predict with each model
for img, key in zip(imgs, modality_keys):
pil_img = PILImage.create(img)
pred, _, probs = models[key].predict(pil_img)
predictions.append(pred)
# Assuming binary classification, extract the probability for the predicted class
prob_pred = probs.max() # Get the highest probability score
detailed_predictions.append(f"{key}: {pred} ({prob_pred:.2f}%)") # Format prediction with percentage
# Majority vote for final decision
final_decision = max(set(predictions), key=predictions.count)
detailed_predictions.append(f"Final Decision: {final_decision}") # Add the final decision
return "\n".join(detailed_predictions) # Return detailed predictions as a single string
# Define the Gradio interface inputs and outputs
inputs = [gr.Image(label=f"{modality} Image") for modality in modality_keys]
output = gr.Text(label="Predictions")
intf = gr.Interface(fn=classify_images, inputs=inputs, outputs=output,
title="ODD Detection from Multiple Imaging Modalities",
description="Upload images for each modality and receive individual predictions with percentages and a binary prediction for Optic Disk Drusen presence.")
intf.launch(share=True)
|