adding app.py, model + requirements
Browse files- app.py +43 -0
- model/effnetb2_dermamnist.pth +3 -0
- requirements.txt +7 -0
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import torchvision.transforms as transforms
|
| 4 |
+
from medmnist import INFO
|
| 5 |
+
from model import load_model
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
# Class names
|
| 9 |
+
info = INFO["dermamnist"]
|
| 10 |
+
class_names = list(info["label"].values())
|
| 11 |
+
|
| 12 |
+
# Load model
|
| 13 |
+
model = load_model()
|
| 14 |
+
|
| 15 |
+
# Transforms (match training)
|
| 16 |
+
transform = transforms.Compose([
|
| 17 |
+
transforms.Resize((224, 224)),
|
| 18 |
+
transforms.ToTensor(),
|
| 19 |
+
transforms.Normalize(mean=[0.5], std=[0.5])
|
| 20 |
+
])
|
| 21 |
+
|
| 22 |
+
# Prediction function
|
| 23 |
+
def predict(image):
|
| 24 |
+
image = image.convert("RGB")
|
| 25 |
+
input_tensor = transform(image).unsqueeze(0) # Add batch dim
|
| 26 |
+
|
| 27 |
+
with torch.no_grad():
|
| 28 |
+
outputs = model(input_tensor)
|
| 29 |
+
probs = torch.softmax(outputs, dim=1).squeeze().numpy()
|
| 30 |
+
|
| 31 |
+
return {class_names[i]: float(probs[i]) for i in range(len(class_names))}
|
| 32 |
+
|
| 33 |
+
# Gradio UI
|
| 34 |
+
demo = gr.Interface(
|
| 35 |
+
fn=predict,
|
| 36 |
+
inputs=gr.Image(type="pil"),
|
| 37 |
+
outputs=gr.Label(num_top_classes=3),
|
| 38 |
+
title="Skin Disease Classifier",
|
| 39 |
+
description="Upload a skin image and the model will predict potential skin cancer(melanoma), tumor or moles using EfficientNet-B2 fine-tuned on DermMNIST."
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
if __name__ == "__main__":
|
| 43 |
+
demo.launch()
|
model/effnetb2_dermamnist.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9e75206d42c74874ac260b367abb4e02c73381ab7f16cc0e11bdd323faabf17c
|
| 3 |
+
size 31302714
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
torchvision
|
| 3 |
+
gradio
|
| 4 |
+
medmnist
|
| 5 |
+
scikit-learn
|
| 6 |
+
matplotlib
|
| 7 |
+
|