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

Classifying dogs and cats – CNN from scratch

We will use the same architecture with a few minor changes, as listed here:

  • The input dimensions for the first linear layer changes, as the dimensions for our cats and dogs images are 256, 256
  • We add another linear layer to give more flexibility for the model to learn

Let's look at the code that implements the network architecture:

class Net(nn.Module):    def __init__(self):        super().__init__()        self.conv1 = nn.Conv2d(3, 10, kernel_size=5)        self.conv2 = nn.Conv2d(10, 20, kernel_size=5)        self.conv2_drop = nn.Dropout2d()        self.fc1 = nn.Linear(56180, 500)        self.fc2 = nn.Linear(500,50)        self.fc3 = nn.Linear(50, 2)    def forward(self, x):        x = F.relu(F.max_pool2d(self.conv1(x), 2)) x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), ...
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