01 2019 档案
摘要:""" 此代码是针对手写字体的训练:将图片按行依次输入网络中训练 RNN网络相对于LSTM网络很难收敛 """ import torch from torch import nn from torch.autograd import Variable import torchvision.datasets as dsets import torchvision.transforms as tra...
阅读全文
摘要:""" 手写字体的训练 """ import os import torch import torch.nn as nn from torch.autograd import Variable import torch.utils.data as Data import torchvision import matplotlib.pyplot as plt # 超参数 EPOCH = 1 BA...
阅读全文
摘要:""" 常用的网络优化器有四种:SGD, Momentum, RMSprop, Adam通过网络的运行结果可以知道SGD的收敛效果最差 """ import torch import torch.utils.data as Data import torch.nn.functional as F f
阅读全文
摘要:""" 如果整个数据库中图片的数量不是每批数据图片数量的整数倍,体统会将剩余的图片放入最后一批 """ import torch import torch.utils.data as Data torch.manual_seed(1) # reproducible BATCH_SIZE = 5 x = torch.linspace(1, 10, 10) y = torch.linsp...
阅读全文
摘要:""" 通常情况下,提取整个网络要比提取整个网络中的参数要慢点 """ import torch from torch.autograd import Variable import matplotlib.pyplot as plt # 数据 x = torch.unsqueeze(torch.linspace(-1, 1, 100), dim=1) y = x.pow(2) + 0.2*to...
阅读全文
摘要:""" 以下两种搭建网络的效果是一样的,很显然第二种方法是非常简洁的 """ import torch import torch.nn.functional as F # 第一种搭建方法 class Net(torch.nn.Module): def __init__(self, n_feature, n_hidden, n_output): super(Net, se...
阅读全文
摘要:""" pytorch中数据标签默认的数据格式是LongTensor,即64位的整数 """ import torch from torch.autograd import Variable import torch.nn.functional as F import matplotlib.pyplot as plt # 制作数据 n_data = torch.ones(100, 2) x0 ...
阅读全文
摘要:""" 在pytorch中只有Variable可以参与网络的训练 """ import torch from torch.autograd import Variable import torch.nn.functional as F import matplotlib.pyplot as plt x = torch.unsqueeze(torch.linspace(-1, 1, 100), ...
阅读全文
摘要:""" Variable为tensor数据构建计算图,便于网络的运算 """ import torch from torch.autograd import Variable tensor = torch.FloatTensor([[1,2],[3,4]]) # 创建一个tensor类型的数据 variable = Variable(tensor, requires_gr...
阅读全文
摘要:""" pytorch相当于神经网络中的numpy,它是以tensor的形式表示 """ import torch import numpy as np # convert numpy to tensor or vise versa np_data = np.arange(6).reshape((2, 3)) torch_data = torch.from_numpy(np_data) #nu...
阅读全文
浙公网安备 33010602011771号