当前位置:网站首页>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
边栏推荐
- Subnet division and subnet summary
- Thread data sharing and security -threadlocal
- Nacos
- ES6解构语法详解
- pytorch nn.AdaptiveAvgPool2d(1)
- 监听器 Listener
- FCN全卷積網絡理解及代碼實現(來自pytorch官方實現)
- [小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation
- pytorch训练深度学习网络设置cuda指定的GPU可见
- Let's just say I can use thousands of expression packs
猜你喜欢

TEC: Knowledge Graph Embedding with Triple Context

过滤器 Filter

TEC: Knowledge Graph Embedding with Triple Context

ASGNet论文和代码解读2

Depth first traversal of C implementation Diagram -- non recursive code

Develop industrial Internet with the technical advantages of small programs

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

Take you through a circuit board, from design to production (dry goods)

JUC learning

C # realize solving the shortest path of unauthorized graph based on breadth first BFS -- complete program display
随机推荐
监听器 Listener
LeetCode 128最长连续序列(哈希set)
pytorch nn. AdaptiveAvgPool2d(1)
Ridge regression and lasso regression
Nacos
gcc使用、Makefile总结
ASGNet论文和代码解读2
Leetcode:829. 连续整数求和
JUC learning
Stop saying that you can't solve the "cross domain" problem
Feature pyramid networks for object detection
Data exchange JSON
CX5120控制汇川IS620N伺服报错E15解决方案
Leetcode 1482 guess, how about this question?
Edge Drawing: A combined real-time edge and segment detector 翻译
Redis tutorial
torch.histc
Learning notes for introduction to C language multithreaded programming
The combination of applet container technology and IOT
Finally in promise