|
import torch |
|
from torchvision import models, transforms |
|
from torch import nn, optim |
|
from PIL import Image |
|
import gradio as gr |
|
|
|
|
|
model = models.resnet50(pretrained=True) |
|
model.fc = nn.Linear(model.fc.in_features, 2) |
|
|
|
|
|
transform = transforms.Compose([ |
|
transforms.Resize((224, 224)), |
|
transforms.ToTensor(), |
|
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), |
|
]) |
|
|
|
|
|
def classify_thyroid_image(image): |
|
image = Image.open(image).convert("RGB") |
|
image = transform(image).unsqueeze(0) |
|
model.eval() |
|
|
|
with torch.no_grad(): |
|
output = model(image) |
|
_, predicted = torch.max(output, 1) |
|
|
|
diagnosis = "Thyroid Disease Detected" if predicted.item() == 1 else "No Thyroid Disease" |
|
return diagnosis |
|
|
|
|
|
gr.Interface(fn=classify_thyroid_image, inputs="image", outputs="text").launch() |
|
|