当前位置:网站首页>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
- IPv4 and IPv6, LAN and WAN, gateway, public IP and private IP, IP address, subnet mask, network segment, network number, host number, network address, host address, and IP segment / number - what does
- 用小程序的技术优势发展产业互联网
- split(),splice(),slice()傻傻分不清楚?
- GCC usage, makefile summary
- 伺服第二编码器数值链接到倍福PLC的NC虚拟轴做显示
- RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
- LeetCode 128最长连续序列(哈希set)
- Learning notes for introduction to C language multithreaded programming
- [小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation
猜你喜欢

Hal library setting STM32 interrupt

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

完全背包问题

Gorilla/mux framework (RK boot): RPC error code design

Kmeans

CX5120控制汇川IS620N伺服报错E15解决方案

JUC learning

Develop industrial Internet with the technical advantages of small programs

监听器 Listener
![[小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation](/img/b3/887d3fb64acbf3702814d32e2e6414.png)
[小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation
随机推荐
Explain spark operation mode in detail (local+standalone+yarn)
How do I use Google Chrome 11's Upload Folder feature in my own code?
C # realize solving the shortest path of unauthorized graph based on breadth first BFS -- complete program display
伺服第二编码器数值链接到倍福PLC的NC虚拟轴做显示
Go tool cli for command line implementation
pytorch训练深度学习网络设置cuda指定的GPU可见
Stop saying that you can't solve the "cross domain" problem
Let's just say I can use thousands of expression packs
后台系统页面左边菜单按钮和右边内容的处理,后台系统页面出现双滚动
ECMAScript 6.0
Finally in promise
衡量两个向量相似度的方法:余弦相似度、pytorch 求余弦相似度:torch.nn.CosineSimilarity(dim=1, eps=1e-08)
pytest-fixture
多元线性回归
雪崩问题以及sentinel的使用
Design of serial port receiving data scheme
Mybati SQL statement printing
Edge Drawing: A combined real-time edge and segment detector 翻译
[reading notes] copywriting realization -- four golden steps for writing effective copywriting
Feature pyramid networks for object detection