20.03.2021 Views

Deep-Learning-with-PyTorch

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

396 CHAPTER 13 Using segmentation to find suspected nodules

This looks very similar to the writer.add_scalar calls we’ve seen before. The dataformats='HWC'

argument tells TensorBoard that the order of axes in our image has

our RGB channels as the third axis. Recall that our network layers often specify outputs

that are B × C × H × W, and we could put that data directly into TensorBoard as

well if we specified 'CHW'.

We also want to save the ground truth that we’re using to train, which will form the

top row of our TensorBoard CT slices we saw earlier in figure 13.16. The code for that

is similar enough to what we just saw that we’ll skip it. Again, check p2ch13/training.py

if you want the details.

13.6.5 Updating our metrics logging

To give us an idea how we are doing, we compute per-epoch metrics: in particular,

true positives, false negatives, and false positives. This is what the following listing

does. Nothing here will be particularly surprising.

Listing 13.31

training.py:400, .logMetrics

sum_a = metrics_a.sum(axis=1)

allLabel_count = sum_a[METRICS_TP_NDX] + sum_a[METRICS_FN_NDX]

metrics_dict['percent_all/tp'] = \

sum_a[METRICS_TP_NDX] / (allLabel_count or 1) * 100

metrics_dict['percent_all/fn'] = \

sum_a[METRICS_FN_NDX] / (allLabel_count or 1) * 100

metrics_dict['percent_all/fp'] = \

sum_a[METRICS_FP_NDX] / (allLabel_count or 1) * 100

Can be larger than 100%

since we’re comparing to

the total number of pixels

labeled as candidate

nodules, which is a tiny

fraction of each image

We are going to start scoring our models as a way to determine whether a particular

training run is the best we’ve seen so far. In chapter 12, we said we’d be using the F1

score for our model ranking, but our goals are different here. We need to make sure

our recall is as high as possible, since we can’t classify a potential nodule if we don’t

find it in the first place!

We will use our recall to determine the “best” model. As long as the F1 score is reasonable

for that epoch, 15 we just want to get recall as high as possible. Screening out

any false positives will be the responsibility of the classification model.

Listing 13.32

training.py:393, .logMetrics

def logMetrics(self, epoch_ndx, mode_str, metrics_t):

# ... line 453

score = metrics_dict['pr/recall']

return score

15 And yes, “reasonable” is a bit of a dodge. “Nonzero” is a good starting place, if you’d like something more

specific.

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

Saved successfully!

Ooh no, something went wrong!