当前位置:网站首页>Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
2022-07-01 03:33:00 【It's seventh uncle】
During the training model , You will encounter a lot of randomness settings , The results of setting randomization and multiple experiments are more convincing . But now more and more papers require the reproducibility of the model , At this time, we have to control the randomness of the code
And the initial weight is the same every time , It is beneficial to the comparison and improvement of the experiment
instructions : There is no direct relationship between random seed and neural network training , The function of random seeds is to produce random numbers with weights as initial conditions . The effect of neural network directly depends on the learning rate and the number of iterations .
To put it simply , The process of generating random numbers in a computer is not random , But its initial number ( seeds ) Is random . In deep learning ,( For example, deep neural network ) We often need to set the initial value of the superparameter in the network , Such as weight , Here we need to use some functions that generate random numbers , These functions are usually seeded manually , If the seed is set to the same , Then the initial weight is the same .
The best random seed should not be found , The existence of randomness is just used to evaluate the robustness of the model . An excellent model , Not because the random initial position is slightly different , And can't find the best location . This is the work that the model itself should resolve , Instead of choosing a random number .

Correlation function :
torch.manual_seed(number): by CPU Set seed in , Generate random number ;torch.cuda.manual_seed(number): For specific GPU Set seeds , Generate random number ;torch.cuda.manual_seed_all(number): For all GPU Set seeds , Generate random number ;
torch.manual_seed(1) It's about setting up CPU The random number of is fixed , Make the same run immediately .py Of documents rand() function ==【 Random function 】== The generated values are fixed and random !
But after setting random seeds , Is every run test.py The output of the file is the same , Instead of the same result every time a random function is generated :
# test.py
import torch
torch.manual_seed(0)
print(torch.rand(1))
print(torch.rand(1))
Output :
tensor([0.4963])
tensor([0.7682])
If you just want to run a random function every time, the result will be the same , As like as two peas, you can set the same random seeds before each random function. :
# test.py
import torch
torch.manual_seed(0)
print(torch.rand(1))
torch.manual_seed(0)
print(torch.rand(1))
Output :
tensor([0.4963])
tensor([0.4963])
Reference resources :【PyTorch】torch.manual_seed() Detailed explanation
边栏推荐
- Research on target recognition and tracking based on 3D laser point cloud
- multiple linear regression
- Go tool cli for command line implementation
- pytorch训练深度学习网络设置cuda指定的GPU可见
- jeecgboot输出日志,@Slf4j的使用方法
- Valid brackets (force deduction 20)
- 网页不能右键 F12 查看源代码解决方案
- Include() of array
- Leetcode: offer 59 - I. maximum value of sliding window
- Bilinear upsampling and f.upsample in pytorch_ bilinear
猜你喜欢

pytorch nn.AdaptiveAvgPool2d(1)

FCN全卷积网络理解及代码实现(来自pytorch官方实现)

Analyze datahub, a new generation metadata platform of 4.7K star
![[us match preparation] complete introduction to word editing formula](/img/e4/5ef19d52cc4ece518e79bf10667ef4.jpg)
[us match preparation] complete introduction to word editing formula

Filter
![[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理](/img/9f/187ca83be1b88630a6c6fbfb0620ed.png)
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理

JUC学习

监听器 Listener

实现pow(x,n)函数

A few lines of transaction codes cost me 160000 yuan
随机推荐
The value of the second servo encoder is linked to the NC virtual axis of Beifu PLC for display
文件上传下载
TEC: Knowledge Graph Embedding with Triple Context
Overview of EtherCAT principle
Error accessing URL 404
Feign remote call and getaway gateway
Edge drawing: a combined real-time edge and segment detector
监听器 Listener
5、【WebGIS实战】软件操作篇——服务发布及权限管理
The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
JUC learning
Clion and C language
Ultimate dolls 2.0 | encapsulation of cloud native delivery
Server rendering technology JSP
[nine day training] content III of the problem solution of leetcode question brushing Report
TEC: Knowledge Graph Embedding with Triple Context
IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
ASGNet论文和代码解读2
EtherCAT简介
C#实现图的深度优先遍历--非递归代码