
PyTorch
lwycc233
坚持总会有回报!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
PyTorch-Numpy和Torch对比
import torch as t import numpy as np np_data = np.arange(6).reshape(2,3) torch_data = t.from_numpy(np_data) # 将array类型转化成tensor类型 tensor2array = torch_data.numpy(); # 将tensor类型转化成array类型 print("--...原创 2019-04-02 19:21:09 · 376 阅读 · 0 评论 -
4.3 优化器
实现随机梯度下降算法(SGD) 应掌握: 优化方法的基本使用方法 如何对模型的不同部分设置不同的学习率 如何调整学习率 import torch as t from torch.autograd import Variable as V from torch import nn #实现随机梯度下降算法(SGD) #首先定义一个LeNet网络 class Net(nn.Module): ...原创 2019-05-10 15:24:48 · 151 阅读 · 0 评论 -
图像卷积
1. tf.nn.conv2d是TensorFlow里面实现卷积的函数 tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None) 除去name参数用以指定该操作的name,与方法有关的一共五个参数: 第一个参数input:指需要做卷积的输入图像,它要求是一个Tensor,具有[batch, in...原创 2019-05-07 15:52:32 · 256 阅读 · 0 评论 -
5.1数据处理-数据加载
学习如何自定义自己的数据集,并可以依次获取 import torch as t from torch.utils import data import os from PIL import Image import numpy as np class DogCat(data.Dataset): def __init__(self,root): imgs = os.lis...原创 2019-05-13 20:31:32 · 198 阅读 · 0 评论 -
4.2.4 损失函数
交叉熵损失CrossEntropyloss import torch as t from torch import nn from torch.autograd import Variable as V #batch_size = 3,计算对应每个类别的分数(只有两个类别) score = V(t.randn(3,2)) print(score) #三个样本分别属于1,0,1类,label必须...原创 2019-05-08 22:09:10 · 160 阅读 · 0 评论 -
4.2.3 循环神经网络层
1. nn.LSTM()参数 input_size: The number of expected features in the input `x` hidden_size: The number of features in the hidden state `h` num_layers: Number of recurrent layers. E.g., setting ``num_laye...原创 2019-05-08 21:54:04 · 324 阅读 · 0 评论 -
4.2.2 激活函数
1.最常用的激活函数ReLU 数学表达式: ReLU(x) = max(0,x) import torch as t from torch import nn from torch.autograd import Variable as V relu = nn.ReLU(inplace=True) # inplace = True代表它会把输出直接覆盖到输入中,这样可以节省内存/显存‘ i...原创 2019-05-08 20:59:03 · 267 阅读 · 0 评论 -
第四章-多层感知机
两个全连接层,采用sigmoid函数作为激活函数 import torch as t from torch import nn from torch.autograd import Variable as V #全连接层 class Linear(nn.Module): # 继承nn.Module def __init__(self,in_features, out_features):...原创 2019-05-06 10:14:50 · 277 阅读 · 0 评论 -
第四章-使用nn.Module实现全连接层
import torch as t from torch import nn from torch.autograd import Variable as V class Linear(nn.Module): # 继承nn.Module def __init__(self,in_features, out_features): print("调用构造函数") ...原创 2019-05-06 09:41:12 · 793 阅读 · 0 评论 -
第三章-利用autograd/Variable实现线性回归
import torch as t from torch.autograd import Variable as V from matplotlib import pyplot as plt from IPython import display #为了在不同的计算机上运行时下面的输出一致,设置随机种子,每次得到的随机数是固定的 t.manual_seed(1000) def get_fake...原创 2019-05-05 22:10:30 · 364 阅读 · 0 评论 -
第三章-利用tensor实现线性回归
import torch as t from matplotlib import pyplot as plt from IPython import display t.manual_seed(1000) # 设置随机种子 def get_fake_data(batch_size = 8): x = t.randn(batch_size,1)*20 # 随机数。batch_size行 1列...原创 2019-05-05 21:23:02 · 219 阅读 · 0 评论 -
PyTorch-Regression回归
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),dim = 1) #将一维变成二维 #调用方法:linspace(x1,x...原创 2019-04-02 21:26:03 · 261 阅读 · 0 评论 -
PyTorch-什么是激励函数(深度学习)
1. 推荐神经网络的激励函数: 卷积神经网络:relu 循环神经网络:relu或者tanh 2. 使用PyTorch实现 import torch as t import torch.nn.functional as F from torch.autograd import variable import matplotlib.pyplot as plt #fake data x = t....原创 2019-04-02 20:18:34 · 250 阅读 · 0 评论 -
PyTorch-Variable变量
Variable和Tensor的形式转化 requires_grad参数涵义 打印Variable梯度 import torch as t from torch.autograd import Variable tensor = t.FloatTensor([[1,2],[3,4]]) variable = Variable(tensor,requires_grad = True) # re...原创 2019-04-02 19:39:47 · 171 阅读 · 0 评论 -
4.4 nn.functional
1. nn.Module 和 nn.functional 不同之处 import torch as t from torch.autograd import Variable as V from torch import nn input = V(t.randn(2,3)) model = nn.Linear(3,4) output1 = model(input) output2 = nn.f...原创 2019-05-10 16:20:15 · 184 阅读 · 0 评论