Module 9: Image Segmentation

1. Learning Objectives

2. What is Image Segmentation?

Image segmentation is the process of partitioning an image into meaningful segments or regions. Unlike object detection, segmentation assigns a label to each pixel.

Semantic vs. Instance Segmentation

3. Key Models and Architectures

4. Applications

5. Lab: Run Semantic Segmentation using DeepLabV3


from torchvision import models
import torchvision.transforms as T
from PIL import Image
import matplotlib.pyplot as plt

# Load a pretrained DeepLabV3 model
model = models.segmentation.deeplabv3_resnet101(pretrained=True).eval()

# Load and preprocess image
img = Image.open("your_image.jpg")
transform = T.Compose([T.Resize(520), T.ToTensor()])
input_tensor = transform(img).unsqueeze(0)

# Run inference
with torch.no_grad():
    output = model(input_tensor)["out"][0]
segmentation = output.argmax(0)

# Display result
plt.imshow(segmentation)
plt.axis('off')
plt.show()

6. Assignment

Objective: Explore segmentation models and perform pixel-wise classification.

Deliverables: Report, input/output images, segmentation mask

Due: End of Week 9