In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to test nn.Dropout in Pytorch, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
Conclusion
The nn.Dropout of Pytorch drops different parameters each time it is called, even if it is the same forward.
If the dropout rate size of the dropout used many times in the model is the same, use the same dropout layer.
As shown in the code: import torchimport torch.nn as nnclass MyModel (nn.Module): def _ _ init__ (self): super (MyModel, self). _ _ init__ () self.dropout_1 = nn.Dropout (0.5) self.dropout_2 = nn.Dropout (0.5) def forward (self Input): # print (input) drop_1 = self.dropout_1 (input) print (drop_1) drop_1 = self.dropout_1 (input) print (drop_1) drop_2 = self.dropout_2 (input) print (drop_2) if _ name__ ='_ _ main__': I = torch.rand ((5) 5)) m = MyModel () m.forward (I)
The results are as follows:
*\ python.exe * / model.pytensor ([[0.0000, 0.0914, 0.0000, 1.4095, 0.0000], [0.0000, 0.0000, 0.1726, 1.3800, 0.0000], [1.7651,0.0000,0.0000,0.9421,1.5603], [1.0510,1.7290,0.0000,0.0000,0.8565], [0.0000,0.0000,0.0000,0.0000]) tensor ([0.0000] 0.0000, 0.4722, 1.4095, 0.0000], [0.0416, 0.0000, 0.1726, 1.3800, 1.3193], [0.0000, 0.3401,0.6550,0.0000,0.0000], [1.0510,1.7290,1.5515,0.0000,0.0000], [0.6388,0.0000,0.00001.0122,0.0000]) tensor ([0.0000,0.0000,0.4722,0.00001.2689] [0.0416, 0.0000, 0.0000, 1.3800, 0.0000], [0.0000, 0.0000, 0.6550, 0.0000, 1.5603], [0.0000, 0.0000, 1.5515, 1.4596, 0.0000], [0.0000, 0.0000, 0.0000, 0.0000, 0.0000]]) Process finished with exit code 0 thank you for reading this article carefully I hope the article "how to Test nn.Dropout in Pytorch" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.