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
Hands-On Neural Networks

You're reading from  Hands-On Neural Networks

Product type Book
Published in May 2019
Publisher Packt
ISBN-13 9781788992596
Pages 280 pages
Edition 1st Edition
Languages
Authors (2):
Leonardo De Marchi Leonardo De Marchi
Profile icon Leonardo De Marchi
Laura Mitchell Laura Mitchell
Profile icon Laura Mitchell
View More author details
Toc

Table of Contents (16) Chapters close

Preface 1. Section 1: Getting Started
2. Getting Started with Supervised Learning 3. Neural Network Fundamentals 4. Section 2: Deep Learning Applications
5. Convolutional Neural Networks for Image Processing 6. Exploiting Text Embedding 7. Working with RNNs 8. Reusing Neural Networks with Transfer Learning 9. Section 3: Advanced Applications
10. Working with Generative Algorithms 11. Implementing Autoencoders 12. Deep Belief Networks 13. Reinforcement Learning 14. Whats Next? 15. Other Books You May Enjoy

Implementing TL in PyTorch

Now we will see how it's possible to implement TL in PyTorch by performing the following steps. We will use a standard training set, cats and dogs, and a pre-trained network:

  1. Import the necessary libraries as follows:
import torch
import torchvision
import torch.nn as nn
import numpy as np
import torch.optim as optim
from torchvision import models
from torchvision import transforms
import copy
import os
from os import listdir
import shutil
from torchvision import datasets
import random
from torch.optim import lr_scheduler
import matplotlib.pyplot as plt
  1. Now, we will use a handy PyTorch function:
# # Create train and test dataset

data_dir = os.path.join('kagglecatsanddogs_3367a','PetImages')

# # Create the train and test set folder
train_dir = os.path.join(data_dir, 'train')
validation_dir = os.path.join(data_dir, 'validation...
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