Pytorch
h_astro
天文爱好者中的码农
展开
-
Pytorch 实现多层网络
Pytorch 实现多层网络 参考学习花书多层感知机的简洁实现 import torch from torch import nn from torch.nn import init import numpy as np import sys sys.path.append("..") import d2lzh_pytorch as d2l # 1 定义模型 num_inputs, num_...原创 2019-08-13 21:13:53 · 1315 阅读 · 3 评论 -
Pytorch理解更多神经网络优化方法
PyTorch种优化器选择 SGD、Momentum、RMSprop、Adam import torch import torch.nn.functional as F from torch.autograd import Variable import matplotlib.pyplot as plt # 超参数 torch.manual_seed(1) LR = 0.01 Batch_siz...原创 2019-08-18 22:36:19 · 132 阅读 · 0 评论 -
numpy线性回归 Pytorch线性回归及神经网络
numpy 梯度下降法 线性回归 import numpy as np import matplotlib.pyplot as plt def get_fake_data(batch_size=8): ''' 产生随机数据:y=x*2+3,加上了一些噪声''' x = np.random.rand(batch_size, 1) * 5 y = x * 2 + 3 + np....原创 2019-08-09 21:12:20 · 840 阅读 · 0 评论 -
PyTorch实现Logistic Regression
1.PyTorch基础实现Logistic regression import torch from torch.autograd import Variable torch.manual_seed(2) x_data = Variable(torch.Tensor([[1.0], [2.0], [3.0], [4.0]])) y_data = Variable(torch.Tensor([[...原创 2019-08-11 21:34:46 · 416 阅读 · 0 评论 -
PyTorch手写数字识别
PyTorch手写数字识别 import numpy as np import torch from torch import nn, optim import torch.nn.functional as F from torch.autograd import Variable from torch.utils.data import DataLoader from torchvision i...原创 2019-08-21 15:19:30 · 346 阅读 · 0 评论 -
PyTorch实现L1,L2正则化以及Dropout
PyTorch实现L1,L2正则化以及Dropout 模型训练中经常出现的两类典型问题: 一类是模型无法得到较低的训练误差,我们将这一现象称作欠拟合(underfitting); 另一类是模型的训练误差远小于它在测试数据集上的误差,我们称该现象为过拟合(overfitting)。 在实践中,我们要尽可能同时应对欠拟合和过拟合。 过拟合现象,即模型的训练误差远小于它在测试集上的误差。虽然增大训练...原创 2019-08-16 21:56:24 · 1111 阅读 · 1 评论