Views
No views yet
U-Net based semantic segmentation of COVID-19 infected regions in lung CT scans.
⚠️ For research and educational purposes only — not a medical device.
| Property | Details |
|---|---|
| 🏗️ Architecture | U-Net |
| 🎯 Task | Semantic Segmentation |
| 🖼️ Input | Lung CT scan slices (grayscale) |
| 🎭 Output | Binary mask — infected vs. healthy tissue |
| 📐 Input size | 256 × 256 px |
| ⚙️ Framework | PyTorch |
| 📜 License | MIT |
| Metric | Score |
|---|---|
| Dice Coefficient | > 0.85 |
| Task | Binary segmentation (infected / healthy) |
1import torch
2from torchvision import transforms
3from PIL import Image
4import numpy as np
5
6# Load model
7model = torch.jit.load("unet_model.pt", map_location="cpu")
8model.eval()
9
10# Preprocessing
11transform = transforms.Compose([
12 transforms.Resize((256, 256)),
13 transforms.Grayscale(),
14 transforms.ToTensor(),
15 transforms.Normalize([0.5], [0.5]),
16])
17
18# Inference
19image = Image.open("ct_scan_slice.png")
20tensor = transform(image).unsqueeze(0)
21
22with torch.no_grad():
23 output = model(tensor)
24 mask = torch.sigmoid(output).squeeze().numpy()
25
26# Binary mask
27binary_mask = (mask > 0.5).astype(np.uint8) * 255
28
29# Percentage of infected area
30infected_pct = binary_mask.mean() / 255 * 100
31print(f"Infected area: {infected_pct:.1f}%")