Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Deep Learning with PyTorch Workshop

You're reading from  The Deep Learning with PyTorch Workshop

Product type Book
Published in Jul 2020
Publisher Packt
ISBN-13 9781838989217
Pages 330 pages
Edition 1st Edition
Languages
Author (1):
Hyatt Saleh Hyatt Saleh
Profile icon Hyatt Saleh
Toc

4. Convolutional Neural Networks

Activity 4.01: Building a CNN for an Image Classification Problem

Solution

  1. Import the required libraries:
    import numpy as np
    import torch
    from torch import nn, optim
    import torch.nn.functional as F
    from torchvision import datasets
    import torchvision.transforms as transforms
    from torch.utils.data.sampler import SubsetRandomSampler
    from sklearn.metrics import accuracy_score
    import matplotlib.pyplot as plt
  2. Set the transformations to be performed on the data, which will be converting the data into tensors and normalizing the pixel values:
    transform = \
        transforms.Compose([transforms.ToTensor(), \
                            transforms.Normalize((0.5, 0.5, 0.5),\
                            ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime