PyTorch Example
Let us consider a PyTorch example of using a neural network to carry out image classification for the FashionMNIST dataset. (This is one of a few different examples described earlier in this topic.) This example is described in the Quickstart Tutorial. The source code itself on Github is linked on that page, can be found on Github, and is reproduced in full in the code box below.
In short, the code below uses the PyTorch API in order to load the FashionMNIST dataset, construct a PyTorch Sequential neural network that includes two hidden layers composed of linear elements, and then train and test the model on the FashionMNIST training and testing sets. In comparison with the TensorFlow/Keras example that we considered previously, a few things are worth highlighting. First, this PyTorch example does not use convolutional layers as part of the neural network as in the other example. Second, the training/fitting process is explicitly programmed via multiple lower-level steps, rather than being bundled up in a single model.fit
method as in the Keras API. This reflects to some extent the design philosophy of PyTorch, to more fully expose the software components needed to enable users to customize their neural network processing. But just as Keras serves as a higher-level API that hides some of the internals of the TensorFlow framework, there are other packages in the PyTorch ecosystem (such as fast.ai and PyTorch Lightning) that aim to provide a higher-level encapsulation of core PyTorch functionality.
We will return in subsequent pages to demonstrate how to install the relevant PyTorch packages and run this sample code on the Frontera system at TACC.