liveBook · Manning

Lung nodule

As explained in Deep Learning with PyTorch, Second Edition

A small tumor in the lung, often only a few millimeters wide, that may later be classified as malignant or not.

A lung nodule is a small tumor in the lung. In a CT scan, it can be only a few millimeters wide and difficult to distinguish from blood vessels and other ordinary structures. Finding a nodule and deciding whether it is malignant are separate questions. section 11.4.1

A whole CT scan is a difficult starting point for a model: even when a nodule is present, nearly all voxels lie outside it. A practical first step is to examine one suspected location, or candidate, at a time. Some candidates are nodules; others are not. section 11.4.1 section 12.4.4

Figure 12.9 Cropping a candidate sample out of the larger CT voxel array using the candidate center’s array coordinate information (I,R,C)
figure

The diagram shows how a candidate’s center is used to crop a small voxel array from the full CT scan. section 12.4.4

Turning candidate locations into model inputs involves three practical steps:

  • Match annotations to candidates, allowing for small differences between recorded center coordinates. A roughly 5 mm nodule, for example, has centers listed about half a millimeter apart in two CSV files. section 12.2.1
  • Convert the center from patient X, Y, Z coordinates to CT array coordinates, then crop a chunk around it. The example crop routine leaves out some boundary-handling complications. section 12.4.4
  • Return the crop and its nodule-or-not label through a PyTorch Dataset. A dataset can collect samples from many CT scans without requiring the model to handle each scan separately. section 12.5

A candidate as a training sample

One LunaDataset sample contains a CT crop tensor, a label such as [0, 1] for a nodule, the scan identifier, and the candidate’s array-coordinate center. Sorting nodules by size and taking every Nth one for validation helps retain a spread of sizes in that set. section 12.5 section 12.2.1

To find suspected nodules across a scan, segmentation asks a different question: which pixels belong to an area of interest? CT data is three-dimensional, but the Segment Anything Model (SAM) accepts two-dimensional images, so individual CT slices are used. Point annotations must be turned into masks for training; this slice-based approach does not directly use the full 3D volume or exact slice thickness. section 15.6.1 section 15.6.2

A fine-tuned SegFormer can then segment nodule areas on unseen slices without the point prompt required by the initial SAM workflow. Those areas can be passed to a classification model. section 15.7.1

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Works through candidate cropping, dataset samples, and slice-based mask preparation, while deferring crop-boundary complications.
Examples
Shows mismatched CSV centers for a roughly 5 mm nodule and a dataset sample containing a labeled CT crop.
What it assumes
Assumes access to CT scans and candidate annotations, while demonstrating how to implement a PyTorch Dataset subclass.
What you can do after
Build it from scratch as a labeled CT-crop dataset, then apply SegFormer to segment areas for classification.
How it connects
Connects CT scans and coordinate conversion to PyTorch Dataset, classification, and semantic segmentation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.