pytorch gan网络_使用pytorch构建自己的生成对抗网络gan

pytorch gan网络

Generative Adversarial Networks is the most interesting idea in machine learning in last ten years.

生成对抗网络是过去十年中机器学习中最有趣的想法。

— Yann Lecun (Facebook AI Director)

— Yann Lecun(Facebook AI总监)

So have you heard about GANs? Or have you just started learning it? GANs was first introduced in 2014 by Ian Goodfellow, a Ph.D. Student at the University of Montreal. The most common example of GANs is generating images. There is a website that contains faces of people that does not exist. This is one of the examples of what GANs can do. That what we are are going to build in this lesson.

那么您是否听说过GAN? 还是刚刚开始学习? GANs由Ian Goodfellow博士于2014年首次提出。 蒙特利尔大学学生。 GAN的最常见示例是生成图像。 有一个网站包含不存在的人的面Kong。 这是GAN可以执行的示例之一。 这就是我们将在本课程中建立的内容。

Generative Adversarial Networks consists of two neural networks Generator and Discriminator competing with each other. I would be explaining each step in detail later in this lesson. If you’re completely unfamiliar with this topic. I would suggest you go through the following lessons first.

生成对抗网络由两个神经网络生成器鉴别器相互竞争。 我将在本课程的后面详细解释每个步骤。 如果您完全不熟悉此主题。 我建议您先学习以下课程。

At the end of this lesson, you’ll be able to train and build your own generative adversarial network from scratch. So without further ado let’s dive in.

在本课程结束时,您将可以从头开始训练并建立自己的生成对抗网络。 因此,事不宜迟,让我们开始吧。

I have also built this generative network in Google Colab here. You can easily open in Google Colabatory and easily follow along.

我还在这里在Google Colab中建立了这个生成网络。 您可以轻松地在Google Colabatory中打开并轻松进行后续操作。

前方的路 (The Road Ahead)

  • Step 0: Import Datasets

    步骤0:导入数据集
  • Step 1: Loading and Preprocessing of Images

    步骤1:图像的加载和预处理
  • Step 2: Define the Discriminator Algorithm

    步骤2:定义识别器算法
  • Step 3: Define the Generator Algorithm

    步骤3:定义生成器算法
  • Step 4: Write the training Algorithm

    步骤4:编写训练算法
  • Step 5: Train the Model

    步骤5:训练模型
  • Step 6: Test the Model

    步骤6:测试模型

So Are you excited??? Let’s dive in!

所以你兴奋吗??? 让我们潜入吧!

步骤0:导入数据集 (Step 0: Import Datasets)

The first step is to download and load the data into memory. So we’ll do that here. We’ll be using the CelebFaces Attributes Dataset (CelebA) to train your adversarial networks.

第一步是将数据下载并加载到内存中。 所以我们在这里做。 我们将使用CelebFaces属性数据集(CelebA)来训练您的对抗网络。

  • Download the dataset from here.

    此处下载数据集。

  • Unzip the dataset.

    解压缩数据集。
  • Clone this Github repository.

    克隆此Github 存储库

After doing that you can either open it in a colab environment or you can use your own pc to train the model.

之后,您可以在colab环境中将其打开,也可以使用自己的PC来训练模型。

导入必要的库 (Import the necessary libraries)

It is always considered as a good practice to import all the libraries you’d be using in the first block of the notebook.

始终将导入要在笔记本第一块中使用的所有库作为一种好习惯。

#import the neccessary libraries
import pickle as pkl
import matplotlib.pyplot as plt
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torch
from torchvision import datasets
from torchvision import transforms
import torch
import torch.optim as optim

步骤1:图像的加载和预处理 (Step 1: Loading And Preprocessing of Images)

In this step, we’re going to preprocess the image data that we’ve downloaded in the previous section.

在这一步中,我们将预处理在上一节中下载的图像数据。

The following step would be taken

将采取以下步骤

  1. Resize the images

    调整图像大小
  2. Convert it into tensors

    将其转换为张量
  3. Load it into PyTorch Dataset

    将其加载到PyTorch数据集中
  4. Load it into PyTorch DataLoader

    </

  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值