当前位置:网站首页>1. Introduction to pytorch
1. Introduction to pytorch
2022-07-27 05:58:00 【Pie star's favorite spongebob】
List of articles
One . Development
2002 year Torch
2011 year Torch7
2016.10 Release PyTorch0.1,THNN Back end
2018.12 Release 1.0,CAFFE2 Back end
2019.5 Release 1.1
Two . Homogeneous framework
Google:keras,TensorFlow
Amazon:MXNet
Facebook:Caffe2,PyTorch
PyTorch and TensorFlow difference
1. Dynamic graph
Similar to human thinking mode , Calculate directly with specific values each time and get the results .
PyTorch It's a motion picture .
2. Static diagram
It's like defining a formula first , Every time we will give a specific value again , The calculation result of the formula will be substituted in the runtime , Create formula and run two separate segments , Static expression cannot be changed after the formula is created .
TensorFlow1 It's a static graph ,TensorFlow2 It is the combination of dynamic graph and static graph .
3. summary
As a researcher or novice , recommend PyTorch, Easy to use , Focus more on algorithms .
As an engineer , recommend TensorFLow2, Better industrial layout .
3、 ... and .PyTorch Simple features
1.GPU Speed up
import torch
import time
print(torch.torch_version)
print(torch.cuda.is_available())
# Two matrices
a = torch.randn(10000,1000)
b = torch.randn(1000,2000)
# Use cpu Calculate the multiplication of the matrix , And record the calculation time 0
t0 = time.time()
c = torch.matmul(a,b)
t1 = time.time()
print(a.device,t1-t0,c.norm(2))
# Use GPU Calculation
device = torch.device('cuda')
a = a.to(device)
b = b.to(device)
t0 = time.time()
c = torch.matmul(a,b)
t1 = time.time()
print(a.device,t1-t0,c.norm(2))
# Calculate the verification result again
t0 = time.time()
c = torch.matmul(a,b)
t1 = time.time()
print(a.device,t1-t0,c.norm(2))
use CPU The running time is 0.1456127166748047, use GPU The first run time is 0.38901543617248535, Than CPU Also big , Because it is the first time to adopt CUDA Will initialize the environment , This time is an inaccurate calculation of time , The second time may be because the calculation is too fast , Direct display 0.
Make the matrix bigger :
a = torch.randn(10000,1000)
b = torch.randn(1000,8000)
The result is :

2. Automatic derivation
import torch
from torch import autograd
x = torch.tensor(1.)
a = torch.tensor(1.,requires_grad=True)
b = torch.tensor(2.,requires_grad=True)
c = torch.tensor(3.,requires_grad=True)
y = a**2 * x + b * x + c
print('before:',a.grad,b.grad,c.grad)
# Start derivation
grads = autograd.grad(y,[a,b,c])
print('after:',grads[0],grads[1],grads[2])
For this formula y, Yes a To find a partial derivative 2ax, Yes b To find a partial derivative x, Yes c To find a partial derivative 1.

3. Common network layer
nn.Linear
nn.Conv2d
nn.LSTM
nn.ReLU
nn.Sigmod
nn.Softmax
nn.CrossEntropyLoss
nn.MSE
边栏推荐
- mysql优化sql相关(持续补充)
- 17.动量与学习率的衰减
- 「中高级试题」:MVCC实现原理是什么?
- 3.分类问题---手写数字识别初体验
- GBASE 8C——SQL参考6 sql语法(3)
- GBASE 8C——SQL参考6 sql语法(6)
- Count the quantity in parallel after MySQL grouping
- GBASE 8C——SQL参考6 sql语法(7)
- Gbase 8C - SQL reference 6 SQL syntax (7)
- How to not overwrite the target source data when dBSwitch data migrates data increments
猜你喜欢

Day 3. Suicidal ideation and behavior in institutions of higher learning: A latent class analysis

数字图像处理——第九章 形态学图像处理

Day 6. Analysis of the energy transmission process of network public opinion in major medical injury events * -- Taking the "Wei Zexi incident" as an example

If you encounter oom online, how to solve it?

Day 9. Graduate survey: A love–hurt relationship

Day14. Using interpretable machine learning method to distinguish intestinal tuberculosis and Crohn's disease

How can I get the lowest handling charge for opening a futures account?

Do you really know session and cookies?

Emoji表情符号用于文本情感分析-Improving sentiment analysis accuracy with emoji embedding

15.GPU加速、minist测试实战和visdom可视化
随机推荐
Day 4.Social Data Sentiment Analysis: Detection of Adolescent Depression Signals
If you encounter oom online, how to solve it?
MySQL如何执行查询语句
GBASE 8C——SQL参考6 sql语法(5)
根据文本自动生成UML时序图(draw.io格式)
如果面试官问你 JVM,额外回答“逃逸分析”技术会让你加分
ES对比两个索引的数据差
Day 3. Suicidal ideation and behavior in institutions of higher learning: A latent class analysis
Day 11. Evidence for a mental health crisis in graduate education
数字图像处理第四章——频率域滤波
Uboot supports LCD and HDMI to display different logo images
新冠时空分析——Global evidence of expressed sentiment alterations during the COVID-19 pandemic
10.梯度、激活函数和loss
Day10. Work organization and mental health problems in PhD students
MySQL二级索引中的主键——MySQL存在大量相同数据分页查询优化
Docker deploys the stand-alone version of redis - modify the redis password and persistence method
15.GPU加速、minist测试实战和visdom可视化
Numpy基础学习
GBASE 8C——SQL参考6 sql语法(9)
2021中大厂php+go面试题(1)