Image segmentation assigns a class to every pixel instead of producing one label for an entire image. A 200 × 200 image therefore requires 40,000 pixel classifications. Labels commonly represent objects such as people, horses, cars, or background; the resulting regions can support object detection or precise measurements such as tumor-cell proportions. section 8.0 section 8.1
A practical PyTorch segmentation pipeline follows these steps:
- Load the image and its masks, remove unused alpha channels, move channels first, normalize pixel values, and resize inputs to 256 × 256. section 8.1.1
- Merge separate nucleus masks with a logical OR to form one binary target: 1 for object pixels and 0 for background. section 8.1.1
- Use convolutional layers to preserve spatial outputs; for two classes, produce one logit per pixel and train with BCEWithLogitsLoss. section 8.1.2
- Compare fine-detail convolutional models with pooled and transposed-convolution models before combining both resolutions with U-Net skip connections. section 8.3 section 8.3.1
Nuclei segmentation
For the 2018 Data Science Bowl images, a Dataset returns a normalized three-channel microscope image and a single-channel binary mask. A U-Net can then produce output shaped like (B, 1, W, H), predicting whether each pixel contains a nucleus. section 8.1.1 section 8.3.1
Figure 8.1 Example of an input image (on the left) with the segmented ground-truth labels (on the right) from the PASCAL VOC 2012 dataset. Every pixel has been given a class, with a default “no class” or “background” class given to pixels that are not part of a labeled object.
Use the labeled image pair to inspect how every pixel receives an object or background class in a PASCAL VOC example. section 8.1





