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.

Predicting malignancy

431

fine-tuning. It probably would be good to pull up a few images of that type to see

what’s happening.

ROC AND OTHER CURVES IN TENSORBOARD

As mentioned earlier, TensorBoard does not natively support drawing ROC curves. We

can, however, use the ability to export any graph from Matplotlib. The data preparation

looks just like in section 14.5.2: we use the data that we also plotted in the histogram

to compute the TPR and FPR—tpr and fpr, respectively. We again plot our

data, but this time we keep track of pyplot.figure and pass it to the SummaryWriter

method add_figure.

Listing 14.12

training.py:482, .logMetrics

Sets up a new Matplotlib figure. We usually don’t need it Uses arbitrary pyplot functions

because it is implicitly done in Matplotlib, but here we do.

fig = pyplot.figure()

Adds our figure to TensorBoard

pyplot.plot(fpr, tpr)

writer.add_figure('roc', fig, self.totalTrainingSamples_count)

Because this is given to TensorBoard as an image, it appears under that heading. We

didn’t draw the comparison curve or anything else, so as not to distract you from the

actual function call, but we could use any Matplotlib facilities here. In figure 14.15, we

see again that the depth-2 fine-tuning (left) overfits, while the head-only fine-tuning

(right) does not.

Figure 14.15

Training ROC curves in TensorBoard. A slider lets us go through the iterations.

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

Saved successfully!

Ooh no, something went wrong!