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.

428 CHAPTER 14 End-to-end nodule analysis, and where to go next

14.5.4 More output in TensorBoard

While we are retraining the model, it might be worth looking at a few more outputs

we could add to TensorBoard to see how we are doing. For histograms, TensorBoard

has a premade recording function. For ROC curves, it does not, so we have an opportunity

to meet the Matplotlib interface.

HISTOGRAMS

We can take the predicted probabilities for malignancy and make a histogram of

them. Actually, we make two: one for (according to the ground truth) benign and one

for malignant nodules. These histograms give us a fine-grained view into the outputs

of the model and let us see if there are large clusters of output probabilities that are

completely wrong.

NOTE In general, shaping the data you display is an important part of getting

quality information from the data. If you have many extremely confident correct

classifications, you might want to exclude the leftmost bin. Getting the

right things onscreen will typically require some iteration of careful thought

and experimentation. Don’t hesitate to tweak what you’re showing, but also

take care to remember if you change the definition of a particular metric without

changing the name. It can be easy to compare apples to oranges unless

you’re disciplined about naming schemes or removing now-invalid runs of data.

We first create some space in the tensor metrics_t holding our data. Recall that we

defined the indices somewhere near the top.

Listing 14.10

training.py:31

METRICS_LABEL_NDX=0

METRICS_PRED_NDX=1

METRICS_PRED_P_NDX=2

METRICS_LOSS_NDX=3

METRICS_SIZE = 4

Our new index, carrying the prediction probabilities

(rather than prethresholded predictions)

Once that’s done, we can call writer.add_histogram with a label, the data, and the

global_step counter set to our number of training samples presented; this is similar

to the scalar call earlier. We also pass in bins set to a fixed scale.

Listing 14.11

training.py:496, .logMetrics

bins = np.linspace(0, 1)

writer.add_histogram(

'label_neg',

metrics_t[METRICS_PRED_P_NDX, negLabel_mask],

self.totalTrainingSamples_count,

bins=bins

)

writer.add_histogram(

'label_pos',

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

Saved successfully!

Ooh no, something went wrong!