pytorch

Transformer架构解析及其pytorch实现

这是笔者学习Transformer原文后手动实践的学习笔记。本文结合原文以及部分引文分析了经典transformer的所有结构,笔者使用pytorch搭建了完整的transformer(不使用pytorch封装的transformer),并用自然语言翻译数据集进行验证。关键词:Transformer... ......
Transformer 架构 pytorch

《动手学深度学习 Pytorch版》 7.7 稠密连接网络

7.7.1 从 ResNet 到 DenseNet DenseNet 可以视为 ResNet 的逻辑扩展。 ResNet 将函数展开为 \(f(\boldsymbol{x})=x+g(\boldsymbol{x})\),即一个简单的线性项和一个复杂的非线性项。 若将 \(f\) 拓展成超过两部分,则 ......
深度 Pytorch 网络 7.7

《动手学深度学习 Pytorch版》 7.6 残差网络(ResNet)

import torch from torch import nn from torch.nn import functional as F from d2l import torch as d2l 7.6.1 函数类 如果把模型看作一个函数,我们设计的更强大的模型则可以看作范围更大的函数。为了使函 ......
残差 深度 Pytorch ResNet 网络

《动手学深度学习 Pytorch版》 7.5 批量规范化

7.5.1 训练深层网络 训练神经网络的实际问题: 数据预处理的方式会对最终结果产生巨大影响。 训练时,多层感知机的中间层变量可能具有更广的变化范围。 更深层的网络很复杂容易过拟合。 批量规范化对小批量的大小有要求,只有批量大小足够大时批量规范化才是有效的。 用 \(\boldsymbol{x}\i ......
深度 Pytorch 7.5

pytorch(3) code

import torch import matplotlib.pyplot as plt torch.manual_seed(10) lr = 0.05 # 学习率 # 创建训练数据 x = torch.rand(20, 1) * 10 # x data (tensor), shape=(20, 1 ......
pytorch code

《动手学深度学习 Pytorch版》 7.4 含并行连接的网络(GoogLeNet)

import torch from torch import nn from torch.nn import functional as F from d2l import torch as d2l 7.4.1 Inception块 GoogLNet 中的基本卷积块叫做 Inception 块(大概 ......
GoogLeNet 深度 Pytorch 网络 7.4

Anaconda+GPU安装pytorch

今天搞了半天,才安装上,各种版本问题。最后安装成功: 教程:2023最新pytorch安装教程,简单易懂,面向初学者(Anaconda+GPU)_时宇羽然的博客-CSDN博客 ......
Anaconda pytorch GPU

PyTorch

PyTorch是一个开源的机器学习框架,它提供了丰富的工具和函数来简化深度学习任务的开发和训练。PyTorch使用动态图模型,这意味着它可以在运行时动态构建计算图,这为研究人员和开发者提供了更大的灵活性和可调试性。下面是一些PyTorch的主要特点和功能: 1.动态计算图:PyTorch使用动态计算 ......
PyTorch

【Python深度学习】深度学习框架Tensorflow、Pytorch介绍

深度学习已经成为了人工智能领域的一股重要力量,而深度学习框架则是在这个领域中进行研究和应用的必备工具。常见的深度学习框架包括TensorFlow、PyTorch、Keras、Theano和Caffe等,其中TensorFlow和PyTorch是最受欢迎的两个框架。本文将着重介绍这两个框架的优缺点以及... ......
深度 Tensorflow 框架 Pytorch Python

《动手学深度学习 Pytorch版》 7.3 网络中的网络(NiN)

LeNet、AlexNet和VGG的设计模式都是先用卷积层与汇聚层提取特征,然后用全连接层对特征进行处理。 AlexNet和VGG对LeNet的改进主要在于扩大和加深这两个模块。网络中的网络(NiN)则是在每个像素的通道上分别使用多层感知机。 import torch from torch impo ......
网络 深度 Pytorch 7.3 NiN

pytorch(5)

模型复杂度 ......
pytorch

pytorch学习了解

import torchvision from model1test import * from torch.utils.data import DataLoader from torch.utils.tensorboard import SummaryWriter trian_data=torch ......
pytorch

《动手学深度学习 Pytorch版》 7.2 使用块的网络(VGG)

import torch from torch import nn from d2l import torch as d2l 7.2.1 VGG 块 AlexNet 没有提供一个通用的模板来指导后续的研究人员设计新的网络,如今研究人员转向了块的角度思考问题。通过使用循环和子程序,可以很容易地在任何现 ......
深度 Pytorch 网络 7.2 VGG

pytorch使用

import torch import numpy as np 1. 张量(tensor) 1.1 初始化 data = [[1, 2],[3, 4]] x_data = torch.tensor(data) #从列表初始化 np_array = np.array(data) x_data = to ......
pytorch

pytorch(3)损失函数

损失函数 | Mean-Squared Loss https://zhuanlan.zhihu.com/p/35707643 交叉熵损失函数 https://www.zhihu.com/tardis/zm/art/35709485?source_id=1003 ......
函数 损失 pytorch

pytorch(2) softmax回归

https://tangshusen.me/Dive-into-DL-PyTorch/#/chapter03_DL-basics/3.4_softmax-regression ''' softmax 将未规范化的预测变换为非负数并且总和为1 我们首先对每个未规范化的预测求幂,这样可以保证输出非负。 ......
pytorch softmax

pytorch学习(1)

https://pytorch.zhangxiann.com/1-ji-ben-gai-nian/1.1-pytorch-jian-jie-yu-an-zhuang 激活环境 conda activate nerf 测试cuda可用 安装画图 python3 -m pip install -U pi ......
pytorch

搭建CUDA、CUDNN、Pytorch环境(Windows10/11)

摘要:搭建Windows系统下Cuda+CUDNN环境,注意C盘一定要大,建议1T+SSD 参考: https://blog.csdn.net/weixin_61164016/article/details/127564466 https://blog.csdn.net/qq_43308156/ar ......
Pytorch Windows 环境 CUDNN CUDA

《动手学深度学习 Pytorch版》 6.5 汇聚层

import torch from torch import nn from d2l import torch as d2l 6.5.1 最大汇聚和平均汇聚 汇聚层和卷积层类似,区别在于汇聚层不带包含参数,汇聚操作是确定性的,通常计算汇聚窗口中所有元素的最大值或平均值,即最大汇聚和平均汇聚。 def ......
深度 Pytorch 6.5

《动手学深度学习 Pytorch版》 6.6 卷积神经网络

import torch from torch import nn from d2l import torch as d2l 6.6.1 LeNet LetNet-5 由两个部分组成: - 卷积编码器:由两个卷积核组成。 - 全连接层稠密块:由三个全连接层组成。 模型结构如下流程图(每个卷积块由一个 ......
卷积 神经网络 深度 神经 Pytorch

《动手学深度学习 Pytorch版》 6.4 多输入多输出通道

import torch from d2l import torch as d2l 6.4.1 多输入通道 简言之,多通道即为单通道之推广,各参数对上即可。 def corr2d_multi_in(X, K): # 先遍历“X”和“K”的第0个维度(通道维度),再把它们加在一起 return sum ......
深度 通道 Pytorch 6.4

《动手学深度学习 Pytorch版》 6.7 填充和步幅

6.3.1 填充 虽然我们用的卷积核较小,每次只会丢失几像素,但是如果应用多层连续的卷积层,累积的像素丢失就会很多。解决此问题的方法为填充。 填充后的输出形状将为 \((n_h-k_h+p_h+1)\times(n_w-k_w+p_w+1)\) import torch from torch imp ......
步幅 深度 Pytorch 6.7

Pytorch

创建项目的方式 DataSet类代码实战 read_data.py from torch.utils.data import Dataset from PIL import Image import os class MyData(Dataset): def __init__(self, root_ ......
Pytorch

《动手学深度学习 Pytorch版》 6.2 图像卷积

import torch from torch import nn from d2l import torch as d2l 6.2.1 互相关计算 X = torch.tensor([[0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]]) K = t ......
卷积 深度 图像 Pytorch 6.2

《动手学深度学习 Pytorch版》 6.1 从全连接层到卷积

6.1.1 不变性 平移不变性(translation invariance): 不管检测对象出现在图像中的哪个位置,神经网络的前面几层应该对相同的图像区域具有相似的反应,即为“平移不变性”。 局部性(locality): 神经网络的前面几层应该只探索输入图像中的局部区域,而不过度在意图像中相隔较远 ......
卷积 全连 深度 Pytorch 6.1

【研究生学习】Pytorch基本知识

本篇博客将记录Pytorch的基本知识,包括Pytorch的环境配置、Pytorch的结构,Pytorch的基本操作等 Pytorch环境配置 我是采用在Anaconda下安装Pytorch的方案,关于这个可以参考网上的大佬写的博客,跟着一步步走就行,比如下面这一篇: 在Anaconda下安装Pyt ......
基本知识 研究生 Pytorch 知识

pytorch-多头注意力

多头注意力 在实践中,当给定相同的查询、键和值的集合时,我们希望模型可以基于相同的注意力机制学习到不同的行为,然后将不同的行为作为知识组合起来,捕获序列内各种范围的依赖关系(例如,短距离依赖和长距离依 赖关系)。因此,允许注意力机制组合使用查询、键和值的不同子空间表示(representation ......
多头 注意力 pytorch

《动手学深度学习 Pytorch版》 5.5 读写文件

5.5.1 加载和保存 import torch from torch import nn from torch.nn import functional as F x = torch.arange(4) torch.save(x, 'x-file') # 使用 save 保存 x2 = torch ......
深度 Pytorch 文件 5.5

《动手学深度学习 Pytorch版》 5.6 GPU

5.6.1 计算设备 import torch from torch import nn torch.device('cpu'), torch.device('cuda:0') # cuda等价于cuda:0(只有一块显卡没法试别的块号) (device(type='cpu'), device(ty ......
深度 Pytorch 5.6 GPU

CUDA版本PyTorch安装

安装驱动 显卡为 Nvidia的GTX950M,驱动版本517.48,这个版本的驱动为CUDA_11.7 移动版:GeForce Game Ready 驱动程序 | 517.48 | Windows 11 | NVIDIA 桌面版:GeForce Game Ready 驱动程序 | 517.48 | ......
PyTorch 版本 CUDA