Skip to Content
Deep Learning with PyTorch
book

Deep Learning with PyTorch

by Vishnu Subramanian
February 2018
Intermediate to advanced
262 pages
6h 59m
English
Packt Publishing
Content preview from Deep Learning with PyTorch

Creating a fully connected model and train

We will use a simple linear model, similar to what we used in ResNet and Inception. The following code shows the network architecture which we will be using to train the model:

class FullyConnectedModel(nn.Module):        def __init__(self,in_size,out_size):        super().__init__()        self.fc = nn.Linear(in_size,out_size)    def forward(self,inp):        out = self.fc(inp)        return outfc = FullyConnectedModel(fc_in_size,classes)if is_cuda:    fc = fc.cuda()

We will use the same fit method to train the preceding model. The following code snippet shows the training code, along with the results:

train_losses , train_accuracy = [],[]val_losses , val_accuracy = [],[]for epoch in range(1,10): epoch_loss, epoch_accuracy = fit(epoch,fc,trn_feat_loader,phase='training') ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Deep Learning with PyTorch

Deep Learning with PyTorch

Eli Stevens, Thomas Viehmann, Luca Pietro Giovanni Antiga
Grokking Deep Learning

Grokking Deep Learning

Andrew W. Trask

Publisher Resources

ISBN: 9781788624336Supplemental Content