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.

Updating the dataset for segmentation

375

we could fix, but since we’re not yet convinced that’s the best use of our time and attention,

we’ll let it remain as is for now. 8 Next, we’ll go about adding this mask to our CT class.

CALLING MASK CREATION DURING CT INITIALIZATION

Now that we can take a list of nodule information tuples and turn them into at CTshaped

binary “Is this a nodule?” mask, let’s embed those masks into our CT object.

First, we’ll filter our candidates into a list containing only nodules, and then we’ll use

that list to build the annotation mask. Finally, we’ll collect the set of unique array

indexes that have at least one voxel of the nodule mask. We’ll use this to shape the

data we use for validation.

Listing 13.5

dsets.py:99, Ct.__init__

def __init__(self, series_uid):

# ... line 116

candidateInfo_list = getCandidateInfoDict()[self.series_uid]

Filters for

nodules

self.positiveInfo_list = [

candidate_tup

Gives us a 1D vector (over the

for candidate_tup in candidateInfo_list slices) with the number of voxels

if candidate_tup.isNodule_bool

flagged in the mask in each slice

]

self.positive_mask = self.buildAnnotationMask(self.positiveInfo_list)

self.positive_indexes = (self.positive_mask.sum(axis=(1,2))

.nonzero()[0].tolist())

Takes indices of the mask slices that have a

nonzero count, which we make into a list

Keen eyes might have noticed the getCandidateInfoDict function. The definition isn’t

surprising; it’s just a reformulation of the same information as in the getCandidate-

InfoList function, but pregrouped by series_uid.

Listing 13.6

This can be useful to

keep Ct init from being a

dsets.py:87

performance bottleneck.

@functools.lru_cache(1)

def getCandidateInfoDict(requireOnDisk_bool=True):

candidateInfo_list = getCandidateInfoList(requireOnDisk_bool)

candidateInfo_dict = {}

for candidateInfo_tup in candidateInfo_list:

candidateInfo_dict.setdefault(candidateInfo_tup.series_uid,

[]).append(candidateInfo_tup)

return candidateInfo_dict

Takes the list of candidates for the series UID

from the dict, defaulting to a fresh, empty list

if we cannot find it. Then appends the

present candidateInfo_tup to it.

8

Fixing this issue would not do a great deal to teach you about PyTorch.

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

Saved successfully!

Ooh no, something went wrong!