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.

Pretraining setup and initialization

285

Init model

Initialized

with Random

weights

FuLly

Trained

Init data loaders

LOop over epochs

Training LOop

Load batch tuple

ClaSsify Batch

Calculate LoSs

Record metrics

Update weights

Validation LOop

Load

batch tuple

ClaSsify Batch

Calculate LoSs

Record metrics

11.3.1 Initializing the model and optimizer

Log Metrics

console

tensorboard

Figure 11.3 The training and validation script we will implement in this chapter, with

a focus on the preloop variable initialization

For this section, we are treating the details of LunaModel as a black box. In section 11.4,

we will detail the internal workings. You are welcome to explore changes to the implementation

to better meet our goals for the model, although that’s probably best done

after finishing at least chapter 12.

Let’s see what our starting point looks like.

Listing 11.4

training.py:31, class LunaTrainingApp

class LunaTrainingApp:

def __init__(self, sys_argv=None):

# ... line 70

self.use_cuda = torch.cuda.is_available()

self.device = torch.device("cuda" if self.use_cuda else "cpu")

self.model = self.initModel()

self.optimizer = self.initOptimizer()

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

Saved successfully!

Ooh no, something went wrong!