File size: 1,128 Bytes
4c89a16
 
 
 
c1a1ba5
 
4c89a16
 
 
c1a1ba5
4c89a16
 
 
 
 
 
 
 
 
 
 
 
c1a1ba5
4c89a16
 
 
 
 
 
c1a1ba5
4c89a16
 
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
import torch
from torchvision import models, transforms
from torch import nn, optim
from PIL import Image
import gradio as gr

# Load a pre-trained model (e.g., ResNet50)
model = models.resnet50(pretrained=True)
model.fc = nn.Linear(model.fc.in_features, 2)  # For binary classification (Thyroid: Positive/Negative)

# Define image transformation
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]),
])

# Example function to classify images
def classify_thyroid_image(image):
    image = Image.open(image).convert("RGB")
    image = transform(image).unsqueeze(0)  # Add batch dimension
    model.eval()  # Set the model to evaluation mode

    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

# Create a Gradio interface for image upload and camera input
gr.Interface(fn=classify_thyroid_image, inputs="image", outputs="text").launch()