pytorch学习笔记(二)

pytorch学习笔记(二)

Logistic Regression分类问题

1、torchvision提供了常用的数据集

import torchvision
train_set = torchvision.datasets.MNIST(root='../dataset/mnist',train=True,download=True)
// train是否是训练集,download是否需要下载
test_set = torchvision.datasets.MNIST(root='../dataset/mnist',train=False,download=True)
  • CIFAR-10 dataset:32*32的图片,分为十类

2、some functions

  • Logistic Function : 属于饱和函数。R→[0,1]
    σ ( x ) = 1 1 + e − x   \sigma(x) = \frac{1}{1+e^{-x}}\, σ(x)=1+ex1

  • Sigmoid functions:满足饱和函数、有极限、单调增函数,常说的Sigmoid function通常指Logistic Function。

  • cross-entropy:交叉熵,表示两个分布之间差异性的大小

  • 二分类用的损失函数(BCE):
    l o s s = − ( y   l o g y ^ + ( 1 − y )   l o g ( 1 − y ^ ) ) loss = -(y \, log\widehat{y} +(1-y)\,log(1-\widehat{y})) loss=(ylogy +(1y)log(1y ))
    (加负号使得loss越小越好)

处理多维特征输入

如果输入八维数据,要求输出一维数据,则需要做以下变换:
[ z ( 1 ) ⋮ z ( N ) ] = [ x 1 ( 1 ) … x 8 ( 1 ) ⋮ x 1 ( N ) … x 8 ( N ) ] [ w 1 ⋮ w 8 ] + [ b 1 ⋮ b 8 ] \begin{bmatrix} z^{(1)} \\ \vdots \\ z^{(N)}\end{bmatrix} = \begin{bmatrix} x_1^{(1)}&\dots&x_8^{(1)} \\ \vdots \\ x_1^{(N)}&\dots&x_8^{(N)}\end{bmatrix} \begin{bmatrix} w_1 \\ \vdots \\ w_8\end{bmatrix}+\begin{bmatrix} b_1 \\ \vdots \\ b_8\end{bmatrix} z(1)z(N)=x1(1)x1(N)x8(1)x8(N)w1w8+b1b8

self.linear = torch.nn.Linear(8,1)

加载数据集

  • Dataset:构造数据集。抽象类,不能实例化
    DataLoader:拿出Mini-Batch供快速使用。可以实例化

  • 利用一个样本——解决鞍点问题,耗费时间长
    利用全部Batch——计算速度快,性能不是很好

  • Epoch:利用所有样本的次数
    Batch-Siza:一次前馈/反馈运算所需的样本个数
    Iteration:用batch size迭代的次数

  • shuffle是否打乱顺序

多分类问题

  • Softmax Classifier:保证p>=0且总概率之和为1。先做指数运算,再求sum、divide,得到一个离散的分布。
  • Loss Function:Loss(y_pred,y)= -ylogy_pred
    CrossEntropyLoss <==> LogSoftmax + NLLLoss

输入的图像先转换成tensor,再调用Normalize使其分布在0~1上,以供神经网络训练。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值