Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use PyTorch optimizer

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use PyTorch optimizer". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use PyTorch optimizer.

The function of the optimizer is to manage and update the parameter group. Please build a SGD optimizer and add three groups of parameters through the add_param_group method. The learning rates of the three groups of parameters are 0.01,0.02,0.03,0.9,0.8,0.7 respectively. After the optimizer is built, print the key and value of each element in the param_groups attribute in the optimizer (hint: param_groups is list Each of its elements is a dictionary)

Control optimizerimport torchimport torch.optim as optimtorch.manual_seed (1234) W1 = torch.randn ((2,2), requires_grad=True) w2 = torch.randn ((2,2), requires_grad=True) w3 = torch.randn ((2,2), requires_grad=True) w1.grad = torch.ones ((2,2)) print (w1.grad, w2.grad, w3.grad) optimizer = optim.SGD ([W1], lr=1, momentum=0.9) optimizer.add_param_group ({"params": W2, 'lr': 2) ) optimizer.add_param_group ({"params": W3, 'lr': 3,' momentum': 0.7}) print ("optimizer.param_groups is\ n {}" .format (optimizer.param_groups)) optimizer.step () print (w1, w2, w3)

At this point, I believe you have a deeper understanding of "how to use PyTorch optimizer". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report