fbpx
维基百科

PyTorch

PyTorch是一个开源Python机器学习,基于Torch英语Torch (machine_learning)[2][3][4],底层由C++实现,应用于人工智能领域,如计算机视觉自然语言处理[5]。它主要由Meta Platforms的人工智能研究团队开发[6][7][8]。著名的用途有:特斯拉自动驾驶Uber最初发起而现属Linux基金会项目的概率编程软件Pyro[9],Lightning[10]

PyTorch
原作者Adam Paszke, Sam Gross, Soumith Chintala, Gregory Chanan
開發者Meta AI英语Meta AI
首次发布2016年10月,​6年前​(2016-October
目前版本
  • 1.13.1 (2022年12月16日)[1]
源代码库github.com/pytorch/pytorch
编程语言Python, C++, CUDA
操作系统Linux, macOS, Windows
类型机器学习深度学习
许可协议BSD许可证
网站pytorch.org

概述

PyTorch主要有两大特征:[11]

PyTorch包括torch.autograd、torch.nn、torch.optim等子模块[14]

例子

下面的程序用简单的例子展示这个程序库的低层功能。

import torch dtype = torch.float device = torch.device("cpu") # 本次在CPU上执行所有的计算 # device = torch.device("cuda:0") # 本次在GPU上执行所有的计算  # 建立一个张量并用随机数填充这个张量 a = torch.randn(2, 3, device=device, dtype=dtype) print(a) # 输出张量a # 输出: tensor([[-1.1884, 0.8498, -1.7129], # [-0.8816, 0.1944, 0.5847]])  # 建立一个张量并用随机数填充这个张量 b = torch.randn(2, 3, device=device, dtype=dtype) print(b) # Output of tensor B # 输出: tensor([[ 0.7178, -0.8453, -1.3403], # [ 1.3262, 1.1512, -1.7070]])  print(a*b) # 输出两个张量的乘积 # 输出: tensor([[-0.8530, -0.7183, 2.58], # [-1.1692, 0.2238, -0.9981]])  print(a.sum()) # 输出在张量a中所有元素的总和 # 输出: tensor(-2.1540)  print(a[1,2]) # 输出第2行第3列(0起始)的元素 # 输出: tensor(0.5847)  print(a.max()) # 输出在张量a中的极大值 # 输出: tensor(-1.7129) 

下列代码块展示了nn模块提供的高层功能的例子。例子中定义了具有线性层的神经网络。

import torch from torch import nn # 从PyTorch中导入nn子模块   class NeuralNetwork(nn.Module): # 神经网络被定义为类  def __init__(self): # 在__init__方法中定义诸层和变量  super(NeuralNetwork, self).__init__() # 必须出现在所有网络中  self.flatten = nn.Flatten() # 定义一个压平层  self.linear_relu_stack = nn.Sequential( # 定义诸层的一个堆栈  nn.Linear(28*28, 512), # 线性层有一个输入和输出形状  nn.ReLU(), # ReLU是nn提供的诸多激活函数之一  nn.Linear(512, 512),  nn.ReLU(),  nn.Linear(512, 10),  )   def forward(self, x): # 这个函数定义前向传递。  x = self.flatten(x)  logits = self.linear_relu_stack(x)  return logits 

熟知的例子

YOLO YOLO在2016年被提出,发表在计算机视觉顶会CVPR(Computer Vision and Pattern Recognition)上 因为YOLO这样的Region-free方法只需要一次扫描,也被称为单阶段(1-stage)模型。Region-based方法方法也被称为两阶段(2-stage)方法

Talking-head-anime(Tha) 用一张图片来生成二次元头像 且此图片有以下要求

  • PNG格式
  • 256 x 256。
  • 人物的头必须在中间的128 x 128框中。
  • 必须有4个通道(RGBA)。
  • 不是人物的像素必须有值(0,0,0,0,0)。换句话说,背景必须透明

参考文献

  1. ^ 1.0 1.1 Release 1.13.1. 2022年12月16日 [2022年12月16日]. 
  2. ^ Yegulalp, Serdar. Facebook brings GPU-powered machine learning to Python. InfoWorld. 19 January 2017 [11 December 2017]. (原始内容于2018-07-12). 
  3. ^ Lorica, Ben. Why AI and machine learning researchers are beginning to embrace PyTorch. O'Reilly Media. 3 August 2017 [11 December 2017]. (原始内容于2019-05-17). 
  4. ^ Ketkar, Nikhil. Deep Learning with Python. Apress, Berkeley, CA. 2017: 195–208 [2018-10-02]. ISBN 9781484227657. doi:10.1007/978-1-4842-2766-4_12. (原始内容于2018-07-12) (英语). 
  5. ^ . dl4nlp.info. [2017-12-18]. (原始内容存档于2019-06-21) (英语). 
  6. ^ Patel, Mo. When two trends fuse: PyTorch and recommender systems. O'Reilly Media. 2017-12-07 [2017-12-18]. (原始内容于2019-03-30) (英语). 
  7. ^ Mannes, John. Facebook and Microsoft collaborate to simplify conversions from PyTorch to Caffe2. TechCrunch. [2017-12-18]. (原始内容于2020-07-06) (英语). FAIR is accustomed to working with PyTorch — a deep learning framework optimized for achieving state of the art results in research, regardless of resource constraints. Unfortunately in the real world, most of us are limited by the computational capabilities of our smartphones and computers. 
  8. ^ Arakelyan, Sophia. Tech giants are using open source frameworks to dominate the AI community. VentureBeat. 2017-11-29 [2017-12-18]. (原始内容于2019-03-30) (美国英语). 
  9. ^ Pyro- Deep universal probabilistic programming with Python and PyTorch. [2022-08-31]. (原始内容于2022-09-08). 
  10. ^ Lightning. [2022-09-01]. (原始内容于2022-09-07). Build and train PyTorch models and connect them to the ML lifecycle using Lightning App templates, without handling DIY infrastructure, cost management, scaling, and other headaches. 
  11. ^ . pytorch.org. [2018-06-11]. (原始内容存档于2018-06-15). 
  12. ^ R.E. Wengert. A simple automatic derivative evaluation program. Comm. ACM. 1964, 7: 463–464. doi:10.1145/355586.364791. 
  13. ^ Bartholomew-Biggs, Michael; Brown, Steven; Christianson, Bruce; Dixon, Laurence. Automatic differentiation of algorithms (PDF). Journal of Computational and Applied Mathematics. 2000, 124 (1-2): 171–190. Bibcode:2000JCoAM.124..171B. doi:10.1016/S0377-0427(00)00422-2. 
  14. ^ 14.0 14.1 神经网络与PyTorch实战 Application of Neural Network and PyTorch. 机械工业出版社. 2018. ISBN 9787111605775. 

外部链接

  • 官方网站

pytorch, 是一个开源的python机器学习库, 基于torch, 英语, torch, machine, learning, 底层由c, 实现, 应用于人工智能领域, 如计算机视觉和自然语言处理, 它主要由meta, platforms的人工智能研究团队开发, 著名的用途有, 特斯拉自动驾驶, uber最初发起而现属linux基金会项目的概率编程软件pyro, lightning, 原作者adam, paszke, gross, soumith, chintala, gregory, chanan開發者me. PyTorch是一个开源的Python机器学习库 基于Torch 英语 Torch machine learning 2 3 4 底层由C 实现 应用于人工智能领域 如计算机视觉和自然语言处理 5 它主要由Meta Platforms的人工智能研究团队开发 6 7 8 著名的用途有 特斯拉自动驾驶 Uber最初发起而现属Linux基金会项目的概率编程软件Pyro 9 Lightning 10 PyTorch原作者Adam Paszke Sam Gross Soumith Chintala Gregory Chanan開發者Meta AI 英语 Meta AI 首次发布2016年10月 6年前 2016 October 目前版本1 13 1 2022年12月16日 1 源代码库github wbr com wbr pytorch wbr pytorch编程语言Python C CUDA操作系统Linux macOS Windows类型机器学习和深度学习库许可协议BSD许可证网站pytorch wbr org 目录 1 概述 2 例子 3 熟知的例子 4 参考文献 5 外部链接概述 编辑PyTorch主要有两大特征 11 类似于NumPy的张量计算 可使用GPU加速 基于带自动微分系统 12 13 的深度神经网络 14 PyTorch包括torch autograd torch nn torch optim等子模块 14 例子 编辑下面的程序用简单的例子展示这个程序库的低层功能 import torch dtype torch float device torch device cpu 本次在CPU上执行所有的计算 device torch device cuda 0 本次在GPU上执行所有的计算 建立一个张量并用随机数填充这个张量 a torch randn 2 3 device device dtype dtype print a 输出张量a 输出 tensor 1 1884 0 8498 1 7129 0 8816 0 1944 0 5847 建立一个张量并用随机数填充这个张量 b torch randn 2 3 device device dtype dtype print b Output of tensor B 输出 tensor 0 7178 0 8453 1 3403 1 3262 1 1512 1 7070 print a b 输出两个张量的乘积 输出 tensor 0 8530 0 7183 2 58 1 1692 0 2238 0 9981 print a sum 输出在张量a中所有元素的总和 输出 tensor 2 1540 print a 1 2 输出第2行第3列 0起始 的元素 输出 tensor 0 5847 print a max 输出在张量a中的极大值 输出 tensor 1 7129 下列代码块展示了nn模块提供的高层功能的例子 例子中定义了具有线性层的神经网络 import torch from torch import nn 从PyTorch中导入nn子模块 class NeuralNetwork nn Module 神经网络被定义为类 def init self 在 init 方法中定义诸层和变量 super NeuralNetwork self init 必须出现在所有网络中 self flatten nn Flatten 定义一个压平层 self linear relu stack nn Sequential 定义诸层的一个堆栈 nn Linear 28 28 512 线性层有一个输入和输出形状 nn ReLU ReLU是nn提供的诸多激活函数之一 nn Linear 512 512 nn ReLU nn Linear 512 10 def forward self x 这个函数定义前向传递 x self flatten x logits self linear relu stack x return logits熟知的例子 编辑YOLO YOLO在2016年被提出 发表在计算机视觉顶会CVPR Computer Vision and Pattern Recognition 上 因为YOLO这样的Region free方法只需要一次扫描 也被称为单阶段 1 stage 模型 Region based方法方法也被称为两阶段 2 stage 方法Talking head anime Tha 用一张图片来生成二次元头像 且此图片有以下要求 PNG格式 256 x 256 人物的头必须在中间的128 x 128框中 必须有4个通道 RGBA 不是人物的像素必须有值 0 0 0 0 0 换句话说 背景必须透明参考文献 编辑 1 0 1 1 Release 1 13 1 2022年12月16日 2022年12月16日 Yegulalp Serdar Facebook brings GPU powered machine learning to Python InfoWorld 19 January 2017 11 December 2017 原始内容存档于2018 07 12 Lorica Ben Why AI and machine learning researchers are beginning to embrace PyTorch O Reilly Media 3 August 2017 11 December 2017 原始内容存档于2019 05 17 Ketkar Nikhil Deep Learning with Python Apress Berkeley CA 2017 195 208 2018 10 02 ISBN 9781484227657 doi 10 1007 978 1 4842 2766 4 12 原始内容存档于2018 07 12 英语 Natural Language Processing NLP with PyTorch NLP with PyTorch documentation dl4nlp info 2017 12 18 原始内容存档于2019 06 21 英语 Patel Mo When two trends fuse PyTorch and recommender systems O Reilly Media 2017 12 07 2017 12 18 原始内容存档于2019 03 30 英语 Mannes John Facebook and Microsoft collaborate to simplify conversions from PyTorch to Caffe2 TechCrunch 2017 12 18 原始内容存档于2020 07 06 英语 FAIR is accustomed to working with PyTorch a deep learning framework optimized for achieving state of the art results in research regardless of resource constraints Unfortunately in the real world most of us are limited by the computational capabilities of our smartphones and computers Arakelyan Sophia Tech giants are using open source frameworks to dominate the AI community VentureBeat 2017 11 29 2017 12 18 原始内容存档于2019 03 30 美国英语 Pyro Deep universal probabilistic programming with Python and PyTorch 2022 08 31 原始内容存档于2022 09 08 Lightning 2022 09 01 原始内容存档于2022 09 07 Build and train PyTorch models and connect them to the ML lifecycle using Lightning App templates without handling DIY infrastructure cost management scaling and other headaches PyTorch About pytorch org 2018 06 11 原始内容存档于2018 06 15 R E Wengert A simple automatic derivative evaluation program Comm ACM 1964 7 463 464 doi 10 1145 355586 364791 Bartholomew Biggs Michael Brown Steven Christianson Bruce Dixon Laurence Automatic differentiation of algorithms PDF Journal of Computational and Applied Mathematics 2000 124 1 2 171 190 Bibcode 2000JCoAM 124 171B doi 10 1016 S0377 0427 00 00422 2 14 0 14 1 神经网络与PyTorch实战 Application of Neural Network and PyTorch 机械工业出版社 2018 ISBN 9787111605775 外部链接 编辑官方网站 取自 https zh wikipedia org w index php title PyTorch amp oldid 74981988, 维基百科,wiki,书籍,书籍,图书馆,

文章

,阅读,下载,免费,免费下载,mp3,视频,mp4,3gp, jpg,jpeg,gif,png,图片,音乐,歌曲,电影,书籍,游戏,游戏。