Deep Learning with PyTorch: A 60 Minute Blitz 要点整理

2024-06-14 00:38

本文主要是介绍Deep Learning with PyTorch: A 60 Minute Blitz 要点整理,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Tensor

创建

  • Construct a 5x3 matrix, uninitialized:
x = torch.Tensor(5, 3)
  • Construct a randomly initialized matrix
x = torch.rand(5, 3)

Operation

实现两个tensor的加法:x+y
1.

x + y

2.

torch.add(x, y)

3.giving an output tensor

result = torch.Tensor(5, 3)
torch.add(x, y, out=result)

4.in-place

y.add_(x)

Numpy Bridge

The torch Tensor and numpy array will share their underlying memory locations, and changing one will change the other.

Converting torch Tensor to numpy Array

a = torch.ones(5)
b = a.numpy()

Converting numpy Array to torch Tensor

a = np.ones(5)
b = torch.from_numpy(a)

CUDA Tensors

Tensors can be moved onto GPU using the .cuda function.

if torch.cuda.is_available():x = x.cuda()y = y.cuda()x + y

autograd.Variable

  • .backward()
  • .data
  • .grad: autograd.Variable
  • .creator: autograd.Function. Each variable has a .creator attribute that references a Function that has created the Variable (except for Variables created by the user - their creator is None).

这篇关于Deep Learning with PyTorch: A 60 Minute Blitz 要点整理的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1058886

相关文章

数论入门整理(updating)

一、gcd lcm 基础中的基础,一般用来处理计算第一步什么的,分数化简之类。 LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } <pre name="code" class="cpp">LL lcm(LL a, LL b){LL c = gcd(a, b);return a / c * b;} 例题:

系统优化要点

这是常用的系统优化要考虑的点,在系统设计和代码评审以及代码优化时加以考虑,最大限度提高系统性能:  1. 优化算法,选择合适高效算法,降低不必要递归,循环,多层循环嵌套,避免循环内初始化等。  2. 避免申请过多不必要的内存  3. 及时释放资源,降低资源使用时间,包括内存,IO,网络,数据库等。  4. 使用缓存:缓存常用的,不易变化的。  5. 慎用数据库锁。确

rtmp流媒体编程相关整理2013(crtmpserver,rtmpdump,x264,faac)

转自:http://blog.163.com/zhujiatc@126/blog/static/1834638201392335213119/ 相关资料在线版(不定时更新,其实也不会很多,也许一两个月也不会改) http://www.zhujiatc.esy.es/crtmpserver/index.htm 去年在这进行rtmp相关整理,其实内容早有了,只是整理一下看着方

笔记整理—内核!启动!—kernel部分(2)从汇编阶段到start_kernel

kernel起始与ENTRY(stext),和uboot一样,都是从汇编阶段开始的,因为对于kernel而言,还没进行栈的维护,所以无法使用c语言。_HEAD定义了后面代码属于段名为.head .text的段。         内核起始部分代码被解压代码调用,前面关于uboot的文章中有提到过(eg:zImage)。uboot启动是无条件的,只要代码的位置对,上电就工作,kern

JavaScript整理笔记

JavaScript笔记 JavaScriptJavaScript简介快速入门JavaScript用法基础语法注释关键字显示数据输出innerHTML innerText属性返回值的区别调试 数据类型和变量数据类型数字(Number)字符串(String)布尔值(Boolean)null(空值)和undefined(未定义)数组(Array)对象(Object)函数(Function) 变量

关于回调函数和钩子函数基础知识的整理

回调函数:Callback Function 什么是回调函数? 首先做一个形象的比喻:   你有一个任务,但是有一部分你不会做,或者说不愿做,所以我来帮你做这部分,你做你其它的任务工作或者等着我的消息,但是当我完成的时候我要通知你我做好了,你可以用了,我怎么通知你呢?你给我一部手机,让我做完后给你打电话,我就打给你了,你拿到我的成果加到你的工作中,继续完成其它的工作.这就叫回叫,手机

c语言要点!

其他合法的输入:     1.    3空格 空格4空格 空格 空格5 空格 回车     2.    3回车4空格5回车     3.    3(tab键)4回车5回车     例子2     #include<stdio.h>     #include<stdlib.h>     int main()     {     int a,b,c;     s

站长常用Shell脚本整理分享(全)

站长常用Shell脚本整理分享 站长常用Shell脚本整理分享1-10 站长常用Shell脚本整理分享11-20 站长常用Shell脚本整理分享21-30 站长常用Shell脚本整理分享31-40 站长常用Shell脚本整理分享41-50 站长常用Shell脚本整理分享51-59 长期更新

Nn criterions don’t compute the gradient w.r.t. targets error「pytorch」 (debug笔记)

Nn criterions don’t compute the gradient w.r.t. targets error「pytorch」 ##一、 缘由及解决方法 把这个pytorch-ddpg|github搬到jupyter notebook上运行时,出现错误Nn criterions don’t compute the gradient w.r.t. targets error。注:我用

简单的Q-learning|小明的一维世界(3)

简单的Q-learning|小明的一维世界(1) 简单的Q-learning|小明的一维世界(2) 一维的加速度世界 这个世界,小明只能控制自己的加速度,并且只能对加速度进行如下三种操作:增加1、减少1、或者不变。所以行动空间为: { u 1 = − 1 , u 2 = 0 , u 3 = 1 } \{u_1=-1, u_2=0, u_3=1\} {u1​=−1,u2​=0,u3​=1}