O'Reilly logo

Python Deep Learning Cookbook by Indra den Bakker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. We start by importing the necessary libraries, as follows:
import matplotlib.pyplot as pltimport itertools

import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.autograd import Variable
from torch.utils.data.dataset import Dataset

import torchvision.datasets as dset
import torchvision.transforms as transforms
  1. We then define our discriminator network in a function:
class discriminator(nn.Module):    def __init__(self):
        super(discriminator, self).__init__()
        self.conv1 = nn.Conv2d(1, d, 4, 2, 1, bias=False)
        self.conv2 = nn.Conv2d(d, d*2, 4, 2, 1, bias=False)
        self.conv2_bn = nn.BatchNorm2d(*2)
        self.conv3 = nn.Conv2d(d*2, *4, 4, 2, 1, bias=False)
        self.conv3_bn = nn.BatchNorm2d ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required