当前位置:网站首页>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
边栏推荐
- TEC: Knowledge Graph Embedding with Triple Context
- How to use hybrid format to output ISO files? isohybrid:command not found
- 数据库中COMMENT关键字的使用
- Take you through a circuit board, from design to production (dry goods)
- Go tool cli for command line implementation
- FCN全卷积网络理解及代码实现(来自pytorch官方实现)
- 多元线性回归
- Home online shopping project
- [nine day training] content III of the problem solution of leetcode question brushing Report
- EtherCAT简介
猜你喜欢

Stop saying that you can't solve the "cross domain" problem

Nacos

小程序容器技术与物联网IoT的结合点

Keil5中如何做到 0 Error(s), 0 Warning(s).

C语言多线程编程入门学习笔记

Detailed list of errors related to twincat3 ads of Beifu

Avalanche problem and the use of sentinel

别再说不会解决 “跨域“ 问题啦

RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs

C#实现基于广度优先BFS求解无权图最短路径----完整程序展示
随机推荐
C#实现图的深度优先遍历--非递归代码
Valid brackets (force deduction 20)
JUC learning
Mybati SQL statement printing
Introduction to EtherCAT
md5sum操作
pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
终极套娃 2.0 | 云原生交付的封装
Leetcode 1818 absolute value, sorting, dichotomy, maximum value
Feature pyramid networks for object detection
pytorch nn.AdaptiveAvgPool2d(1)
How do spark tasks of 10W workers run? (Distributed Computing)
ctfshow爆破wp
TEC: Knowledge Graph Embedding with Triple Context
gcc使用、Makefile总结
文件上传下载
【伸手党福利】开发人员重装系统顺序
Avalanche problem and the use of sentinel
Server rendering technology JSP
Explain spark operation mode in detail (local+standalone+yarn)