Views
No views yet
Normal and Oral Cancer1pip install torch torchvision pillow
2
3import torch
4from torchvision import transforms
5from PIL import Image
6
7# Load model
8model = torch.hub.load('mysmile/umlomo', 'model', trust_repo=True)
9model.eval()
10
11# Preprocess image
12transform = transforms.Compose([
13 transforms.Resize((224, 224)),
14 transforms.ToTensor(),
15 transforms.Normalize(mean=[0.485, 0.456, 0.406],
16 std=[0.229, 0.224, 0.225])
17])
18
19image = Image.open('oral_photo.jpg').convert('RGB')
20input_tensor = transform(image).unsqueeze(0)
21
22# Inference
23with torch.no_grad():
24 outputs = model(input_tensor)
25 probs = torch.softmax(outputs, dim=1)
26 pred_idx = torch.argmax(probs, dim=1).item()
27
28class_names = ['Normal', 'Oral Cancer']
29print(f"Prediction: {class_names[pred_idx]}, Confidence: {probs[0][pred_idx]:.2f}")