20.03.2021 Views

Deep-Learning-with-PyTorch

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

288 CHAPTER 11 Training a classification model to detect suspected tumors

Luna Dataset

Data Loader

CT Files

.MHD

Sample tupleS

sample aRray

( ,

sample aRray

( ,

Batch tuple

5d fp32 aRray

( ,

.RAW

is nodule?

T,

is nodule?

F,

1d bOol aRray

[T, F...]

ANnotations

Series_uid

“1.2.3”,

Series_uid

“4.5.6”,

List of Strings

[“123”, “456”...],

.CSV

candidate

location

(I,R,C))

candidate

location

(I,R,C))

List of IRC

tuples

[IRC, IRC...])

Figure 11.4

Sample tuples being collated into a single batch tuple inside a data loader

Conveniently, we don’t have to implement any of this batching: the PyTorch Data-

Loader class will handle all of the collation work for us. We’ve already built the bridge

from the CT scans to PyTorch tensors with our LunaDataset class, so all that remains

is to plug our dataset into a data loader.

Listing 11.5

training.py:89, LunaTrainingApp.initTrainDl

def initTrainDl(self):

train_ds = LunaDataset(

val_stride=10,

isValSet_bool=False,

)

Our custom dataset

batch_size = self.cli_args.batch_size

if self.use_cuda:

batch_size *= torch.cuda.device_count()

train_dl = DataLoader(

train_ds,

batch_size=batch_size,

num_workers=self.cli_args.num_workers,

pin_memory=self.use_cuda,

)

An off-the-shelf class

Batching is done automatically.

Pinned memory transfers

to GPU quickly.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!