
pytorch
bo.qiu_xbw
Talking is cheap ,show me the code.
展开
-
莫烦pytorch(9)——optimizer
1.画图import torchimport torch.utils.data as Dataimport torch.nn.functional as Fimport matplotlib.pyplot as pltLR = 0.01BATCH_SIZE = 32EPOCH = 12x=torch.unsqueeze(torch.linspace(-1,1,1000),di...翻译 2019-02-27 14:32:33 · 346 阅读 · 0 评论 -
莫烦pytorch(7)——保存提取
1.保存网络import torchimport torch.nn.functional as Fimport matplotlib.pyplot as pltx=torch.unsqueeze(torch.linspace(-1,1,100),dim=1)# x data (tensor), shape=(100, 1)y=x.pow(2)+0.2*torch.rand(x.size(...翻译 2019-02-27 11:00:32 · 170 阅读 · 0 评论 -
莫烦pytorch(6)——快速搭建网络
1.画图和第五课的画图代码一致,此处不多讲import torchimport torch.nn.functional as Fimport matplotlib.pyplot as plt#method 1n_data=torch.ones(100,2)x0=torch.normal(n_data*2,1)y0=torch.zeros(100)x1 = torch.norm...翻译 2019-02-27 10:48:39 · 751 阅读 · 0 评论 -
莫烦pytorch(5)———classification
1.画出散点图import torchimport torch.nn.functional as Fimport matplotlib.pyplot as pltn_data=torch.ones(100,2) #类似于np.ones()x0=torch.normal(n_data*2,1)y0=torch.zeros(100)x1 = torch.norma...翻译 2019-02-27 10:40:06 · 236 阅读 · 0 评论 -
莫烦pytorch(4)——regression
1.构造出散点图import torchimport numpy as npimport torch.nn.functional as Fimport matplotlib.pyplot as plt#x=torch.unsqueeze(torch.linspace(-1,1,100),dim=1)## x data (tensor), shape=(100, 1),这里的是把一维变成...翻译 2019-02-26 23:02:06 · 205 阅读 · 0 评论 -
莫烦pytorch(3)
1.各种激励函数首先介绍一下import torch.nn.functional as F,激励函数在里面找,后几章会有import torch.nn as nn,这个里面也存在的激励函数,那么他们有什么区别呢?F.conv2d()类似于python的一个函数,而nn.Conv2d是一个类,他是通过而nn.Conv2d的forward()函数实现是用F.conv2d()实现的import t...翻译 2019-02-26 22:26:43 · 424 阅读 · 0 评论 -
莫烦pytorch(2)
1.tensor转变为Variable变量首先需要解释一个库from torch.autograd import Variable,提到这个库就必须要提到Variable,简而言之,Variable就是一个tensor的外衣,里面有三个属性.data, .grad和.grad_fn(老版的是.creator),其中data属性存储着tensor数据,grad属性存储关于该变量的导数(当然只有BP...翻译 2019-02-26 21:47:53 · 281 阅读 · 0 评论 -
莫烦pytorch(1)
1. torch类型numpy的互相转换import numpy as npimport tensorflow as tfimport torchnp_data = np.arange(6).reshape((2, 3)) #(2,3)torch_data = torch.from_numpy(np_data) #转换成tensortensor2array = torch_d...翻译 2019-02-26 21:05:24 · 320 阅读 · 1 评论 -
莫烦pytorch(16)——BN批标准化
1.构造数据集import torchfrom torch import nnfrom torch.nn import initimport torch.utils.data as Dataimport matplotlib.pyplot as pltimport numpy as npN_SAMPLES = 2000BATCH_SIZE = 64EPOCH = 12LR =...翻译 2019-02-28 09:17:11 · 1185 阅读 · 2 评论 -
莫烦pytorch(15)——过拟合
1.构造数据集import matplotlib.pyplot as pltN_SAMPLES = 20N_HIDDEN = 300x=torch.unsqueeze(torch.linspace(-1,1,N_SAMPLES),1)y=x+0.3*torch.normal(torch.zeros(N_SAMPLES,1),torch.ones(N_SAMPLES,1))# tes...翻译 2019-02-28 09:17:04 · 709 阅读 · 0 评论 -
莫烦pytorch(14)——GAN网络
1.画出大师作品(构造目标)import torchimport torch.nn as nnimport numpy as npimport matplotlib.pyplot as plttorch.manual_seed(1) # 设置种子np.random.seed(1)BATCH_SIZE = 64LR_G = 0.0001 # (生成网络)...翻译 2019-02-27 21:58:43 · 601 阅读 · 1 评论 -
莫烦pytorch(13)——自编码
import torchimport torch.nn as nnimport torch.utils.data as Dataimport torchvisionimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dfrom matplotlib import cmimport numpy as ...翻译 2019-02-27 20:34:03 · 435 阅读 · 0 评论 -
莫烦pytorch(12)——RNN回归
1.构造数据import torchfrom torch import nnimport numpy as npimport matplotlib.pyplot as plt# Hyper ParametersTIME_STEP = 10 # rnn time stepINPUT_SIZE = 1 # rnn input sizeLR = 0.02 ...翻译 2019-02-27 16:55:32 · 483 阅读 · 1 评论 -
莫烦pytorch(11)——RNN分类
1.下载数据集和CNN数据集一致,不多叙述import torchfrom torch import nnimport torchvision.datasets as dsetsimport torchvision.transforms as transformsimport matplotlib.pyplot as plt# torch.manual_seed(1) #设置...翻译 2019-02-27 16:32:29 · 724 阅读 · 0 评论 -
莫烦pytorch(10)——CNN
import torchvision用来生成图片,视频数据集,和一些流行的模型类和预训练模型。1.生成数据集import torchimport torch.nn as nnimport torch.utils.data as Dataimport torchvision # 数据库模块import matplotlib.pyplot as plttorch.manual...翻译 2019-02-27 15:31:59 · 371 阅读 · 0 评论 -
莫烦pytorch(8)——批训练
首先介绍一下import torch.utils.data as Data,这在训练过程中基本都会用到。该接口大多用来读取数据和把数据封装成Tensor,之后的DataLoader用来做mini—batch训练。import torchimport torch.utils.data as DataBATCH_SIZE=5x=torch.linspace(1,10,10)y=torch...翻译 2019-02-27 13:03:35 · 278 阅读 · 0 评论