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.

316 CHAPTER 11 Training a classification model to detect suspected tumors

terminology, and then we’ll come up with a better grading scheme that doesn’t lend

itself to being gamed quite as easily as what we’ve done so far.

11.11 Conclusion

We’ve come a long way this chapter—we now have a model and a training loop, and

are able to consume the data we produced in the last chapter. Our metrics are being

logged to the console as well as graphed visually.

While our results aren’t usable yet, we’re actually closer than it might seem. In

chapter 12, we will improve the metrics we’re using to track our progress, and use

them to inform the changes we need to make to get our model producing reasonable

results.

11.12 Exercises

1 Implement a program that iterates through a LunaDataset instance by wrapping

it in a DataLoader instance, while timing how long it takes to do so. Compare

these times to the times from the exercises in chapter 10. Be aware of the

state of the cache when running the script.

a What impact does setting num_workers=… to 0, 1, and 2 have?

b What are the highest values your machine will support for a given combination

of batch_size=… and num_workers=… without running out of memory?

2 Reverse the sort order of noduleInfo_list. How does that change the behavior

of the model after one epoch of training?

3 Change logMetrics to alter the naming scheme of the runs and keys that are

used in TensorBoard.

a

b

c

Experiment with different forward-slash placement for keys passed in to

writer.add_scalar.

Have both training and validation runs use the same writer, and add the trn

or val string to the name of the key.

Customize the naming of the log directory and keys to suit your taste.

11.13 Summary

• Data loaders can be used to load data from arbitrary datasets in multiple processes.

This allows otherwise-idle CPU resources to be devoted to preparing

data to feed to the GPU.

• Data loaders load multiple samples from a dataset and collate them into a batch.

PyTorch models expect to process batches of data, not individual samples.

• Data loaders can be used to manipulate arbitrary datasets by changing the relative

frequency of individual samples. This allows for “after-market” tweaks to a

dataset, though it might make more sense to change the dataset implementation

directly.

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

Saved successfully!

Ooh no, something went wrong!