Chapter 11: Using PyTorch to fight cancer
This introduction previews the lung cancer project’s overall plan and the data and domain context to be covered in the chapter.
After this chapter you will be able to
- Project input and output. Describe what the project takes as input and what it aims to produce, without treating the result as a clinical tool.
- Choice of challenging use case. Justify why the book chooses lung tumor detection and why it calls for a more structured approach than earlier projects.
- Nonstandard 3D data preparation. Explain why this project requires more work on data before model design than the earlier image-classification project, and how its 3D input affects the tools available.
- Staged problem decomposition. Justify breaking the end-to-end task into simpler problems rather than expecting one direct CT-to-answer model, and describe the intended handoff between steps.
- Domain-informed model development. Explain why understanding the medical problem must accompany neural-network intuition and experimentation.
- CT Volumes Versus X-rays. Distinguish a CT scan from an X-ray by explaining that a CT scan retains three-dimensional data while an X-ray projects it onto a two-dimensional plane. Describe how retaining that third dimension permits different views, including views that hide unwanted tissue types.
- Voxel Values and Appearance. Explain what a CT voxel is and what its numeric value roughly represents. Describe how high- and low-density materials typically appear in CT visualizations.
- Voxel Dimensions and Scanner Motion. Explain why CT voxels need not be cubes: their dimensions represent measurable distances along three axes, and the patient's movement along the head-to-foot axis gives that axis a different measurement process.
- CT-to-diagnosis project pipeline. Trace how the proposed system moves from a full 3D CT scan through data loading, segmentation, and candidate classification toward a whole-patient diagnosis.
- Independent project stages. Explain why the team can develop candidate classification separately from segmentation and why that separation is useful.
- Domain-informed solution design. Justify investigating the clinical problem and CT data before choosing and improving a deep learning approach.
- Sparse cancer signal in CTs. Explain why asking one network to find and classify cancer in entire CT scans is impractical for this project. Describe how little of a scan may be relevant and why simply using more data and training is not a practical answer.
- Focused multistep model tradeoff. Describe the benefit and limitation of training segmentation and classification as separate tasks. Explain why giving the classifier a close-up of an area of interest makes its task more contained.
- Nodules as classifier inputs. Distinguish a nodule from a malignant tumor and explain why the classifier can focus on nodules rather than all tissue.
- LUNA as a research resource. Explain how LUNA combines openly available, labeled CT scans with a public classifier ranking, giving teams a common basis for testing nodule-detection methods and finding ideas for improvement.
- LUNA data setup. Describe where to download the LUNA data, how to arrange its subsets and CSV files, and what must be in place to start the next chapter’s examples.
- Preparation as project progress. Explain why researching the lung-cancer-detection problem and sketching the project's design count as progress before implementation begins.
What it builds on
- Putting it all together for our network (chapter 8) · The earlier convolutional image model provides the comparison for this project.
- 3D images: Volumetric data (chapter 4) · The earlier introduction to representing volumetric data.
Section by section
Introduction
This introduction previews the lung cancer project’s overall plan and the data and domain context to be covered in the chapter.
11.1 Introduction to the use case
Introduces lung tumor detection from CT scans as a realistic PyTorch project, explaining its motivation, engineering challenges, and limits.
- Project input and output: Describe what the project takes as input and what it aims to produce, without treating the result as a clinical tool.
Why it matters: This keeps the technical task distinct from a clinically reliable diagnosis. - Motivation for automated review: Explain why reviewing scans for early lung cancer is a difficult manual task and why automation is appealing.
Why it matters: The difficulty of sustained scan review explains why this is a worthwhile automation problem. - Choice of challenging use case: Justify why the book chooses lung tumor detection and why it calls for a more structured approach than earlier projects.
Why it matters: The example is meant to build problem-solving judgment, not just demonstrate a model that works on the first try.
Key terms: CT scans, suspected malignant tumors, early stages, highly trained specialists, unsolved, structured approach, open source projects
11.2 Preparing for a large-scale project
This section explains why the lung-cancer project needs substantial data preparation, a staged approach, domain understanding, and significant computing resources.
- Nonstandard 3D data preparation: Explain why this project requires more work on data before model design than the earlier image-classification project, and how its 3D input affects the tools available.
Why it matters: The model cannot be the sole focus when the data is not already ready for training. - Staged problem decomposition: Justify breaking the end-to-end task into simpler problems rather than expecting one direct CT-to-answer model, and describe the intended handoff between steps.
Why it matters: Smaller steps make a difficult end-to-end problem more approachable and easier to rethink. - Domain-informed model development: Explain why understanding the medical problem must accompany neural-network intuition and experimentation.
Why it matters: Understanding the problem guides choices that code or a powerful model alone cannot justify. - Project computing requirements: State the practical GPU and disk-space requirements described for training and storing this project's data and models.
Why it matters: These requirements affect whether a reader can train the models and store the project files locally.
Key terms: 3D data, 2D-specific tools, off-the-shelf dataset, training samples, end-to-end result, series of simpler problems, finite computational resources, radiation oncology, problem space, disciplined experimentation
11.3 What is a CT scan, exactly?
The section explains CT scans as three-dimensional data, including what their voxels represent, how scans differ from X-rays, and why acquisition details matter when working with them.
- CT Volumes Versus X-rays: Distinguish a CT scan from an X-ray by explaining that a CT scan retains three-dimensional data while an X-ray projects it onto a two-dimensional plane. Describe how retaining that third dimension permits different views, including views that hide unwanted tissue types.
Why it matters: Thinking of a CT scan as a volume explains both its data layout and the views we can make from it. - Voxel Values and Appearance: Explain what a CT voxel is and what its numeric value roughly represents. Describe how high- and low-density materials typically appear in CT visualizations.
Why it matters: Voxel values connect the numbers in a CT array to the anatomy shown in a visualization. - Voxel Dimensions and Scanner Motion: Explain why CT voxels need not be cubes: their dimensions represent measurable distances along three axes, and the patient's movement along the head-to-foot axis gives that axis a different measurement process.
Why it matters: The scanner's physical operation is a clue that array positions need not correspond to equal distances in every direction. - Limits on CT Availability: Explain why collections of CT scans can be harder to obtain than X-rays, citing scanner cost and staffing as well as patient privacy.
Why it matters: These constraints explain why an existing, organized CT collection is valuable for the project. - Digital CT Interpretation: Describe why raw CT output needs computer interpretation for people to view it and state that scanner settings can substantially affect the resulting data.
Why it matters: A displayed CT image is an interpretation of digital measurements, not simply the scanner's raw output.
Key terms: CT scan, 3D array, single-channel data, X-ray, projection, voxel, 3D grid, numeric value, radiodensity, rectangular prism
11.4 The project: An end-to-end detector for lung cancer
The section lays out a modular path from a chest CT scan to a patient-level lung cancer assessment and explains why the project is divided and informed by clinical knowledge and prior work.
- CT-to-diagnosis project pipeline: Trace how the proposed system moves from a full 3D CT scan through data loading, segmentation, and candidate classification toward a whole-patient diagnosis.
Why it matters: This sequence gives each model and data-processing step a clear role in the overall project. - Nodules and malignancy: Distinguish a lung nodule from malignancy and explain why classifying a candidate as a nodule does not by itself establish cancer.
Why it matters: It keeps the task of finding a real nodule distinct from the harder task of judging whether it is cancerous. - Independent project stages: Explain why the team can develop candidate classification separately from segmentation and why that separation is useful.
Why it matters: Annotated data makes it practical to develop one stage without waiting for every other stage to work. - Domain-informed solution design: Justify investigating the clinical problem and CT data before choosing and improving a deep learning approach.
Why it matters: Knowing the problem space helps direct experiments rather than treating model building as blind trial and error. - Prior work as benchmark: Explain how prior work informs the proposed project structure without replacing the need to understand and test an approach.
Why it matters: Earlier results provide a starting point, not a guarantee or a substitute for understanding your own system.
Key terms: CT scan, segmentation, voxels, nodule candidates, classification, tumor, nodule, benign, malignant, human-annotated
11.4.1 Why can’t we just throw data at a neural network until it works?
This section explains why lung-cancer detection in CT scans is difficult and why the project uses separate, focused models rather than training one network on whole scans.
- Sparse cancer signal in CTs: Explain why asking one network to find and classify cancer in entire CT scans is impractical for this project. Describe how little of a scan may be relevant and why simply using more data and training is not a practical answer.
Why it matters: It explains why a successful approach must narrow down where the model looks. - Focused multistep model tradeoff: Describe the benefit and limitation of training segmentation and classification as separate tasks. Explain why giving the classifier a close-up of an area of interest makes its task more contained.
Why it matters: The split makes the project manageable while making clear that ease of learning comes with a potential performance tradeoff. - Nodules as classifier inputs: Distinguish a nodule from a malignant tumor and explain why the classifier can focus on nodules rather than all tissue.
Why it matters: Knowing what a nodule is explains why finding candidate lumps can simplify cancer classification.
Key terms: CT scan, voxels, end-to-end, segmentation model, classification model, end-to-end gradient backpropagation, zoomed-in view, nodule, benign, malignant tumor
11.4.2 Our data source: The LUNA Grand Challenge
This section explains why the LUNA Grand Challenge is a useful CT-scan data source, how its tracks relate to the project, and why other CT data needs careful checking.
- LUNA as a research resource: Explain how LUNA combines openly available, labeled CT scans with a public classifier ranking, giving teams a common basis for testing nodule-detection methods and finding ideas for improvement.
Why it matters: A shared dataset and ranking make it possible to compare approaches rather than evaluate each one in isolation. - CT data variability: Describe why assumptions that work for the generally clean LUNA data should be checked before incorporating CT scans from other sources.
Why it matters: A method that works on clean LUNA scans may encounter different image conventions or appearances in other CT data. - LUNA challenge tracks: Distinguish LUNA 2016's nodule-detection and false-positive-reduction tracks by relating them to the project's segmentation and classification steps, respectively.
Why it matters: The track names place the project's two model tasks in the context of the LUNA challenge.
Key terms: LUNA Grand Challenge, open dataset, high-quality labels, public ranking, CT scans, voxels, LUNA data, LUNA 2016, Nodule detection (NDET), False positive reduction (FPRED)
11.4.3 Downloading the LUNA data
Explains how to obtain and organize the LUNA data and CSV files, and how disk-space limits affect running the project examples.
- LUNA data setup: Describe where to download the LUNA data, how to arrange its subsets and CSV files, and what must be in place to start the next chapter’s examples.
Why it matters: The examples need the data files in the expected locations before they can run. - Storage and subset tradeoff: Explain the disk space needed for the LUNA data and cache, and the consequence of using fewer subsets.
Why it matters: Planning for the extracted data and cache helps you choose a workable setup without mistaking a reduced-data run for full-model performance.
Key terms: LUNA, subset0 through subset9, candidates.csv, annotations.csv, subsets, cache space, training set
11.5 Conclusion
The conclusion emphasizes that researching the problem and designing the project are meaningful progress even before any code is written.
- Preparation as project progress: Explain why researching the lung-cancer-detection problem and sketching the project's design count as progress before implementation begins.
Why it matters: It helps you recognize important project work that happens before implementation.
Key terms: research and preparation, understanding the space, design work
11.6 Summary
Where this is used later
- Straightforward dataset implementation (chapter 12) · Implementing a dataset requires preparing usable samples from the project data.
- Utilizing a second model in our project (chapter 15) · The use of a second model fits the project's staged approach.
- Data needed for training (chapter 13) · Preparing to run training requires accounting for the project's data storage needs.
- Loading individual CT scans (chapter 12) · Loading individual CT scans relies on understanding that each scan contains volumetric data.
- Hounsfield Units (chapter 12) · The discussion of Hounsfield Units builds on the introductory account of CT voxel values.
- CT scan shape and voxel sizes (chapter 12) · CT scan shape and voxel sizes require attention to physical distances along each axis.
- (chapter intro) (chapter 12) · The lung-cancer detection project and its data sources.
- A foundational model and training loop (chapter 13) · Develops the candidate-classification model and training loop as a distinct task.
Concepts explained in this chapter
- image segmentationA learning task that partitions an input, often an image, into labeled regions or elements, used here to flag voxels or pixels that may belong to a nodule.
- cancerThe property of a tumor being cancerous and capable of harmful growth, as distinguished from benign tissue.
- lung noduleA small tumor in the lung, often only a few millimeters wide, that may later be classified as malignant or not.
- convolutional layerA PyTorch 2D convolution layer module that applies learned filters over spatial input regions.
- LUNA Grand ChallengeA lung nodule analysis dataset containing CT scan data and annotations used here as the source of raw medical imaging samples.
- computed tomographyComputed tomography imaging data consisting of cross-sectional body slices.
- voxelA three-dimensional volume element used to discretize volumetric data.
- lung tumor detectionThe task of automatically identifying suspected malignant lung tumors from chest CT scans.
- classifierA supervised learning task that assigns a text sequence to one of several categories.
- preprocessingData preparation performed before model execution, here separating image and prompt encoding from the main model run.
- trainingThe optimization phase in which a model learns from examples.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
