Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the function of PyTorch reduction?

Shulou Source: shulou.com Published: 2022-06-01 12:47:11 11月04日 Update

This article mainly explains "what is the role of PyTorch reduction". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the role of PyTorch reduction".

There are three modes of reduction of loss function. What are their functions?

How is loss calculated when inputs, target and weight are in reduction='mean' mode with the following parameters, respectively?

Inputs = torch.tensor ([[1,2], [1,3], [1,3]], dtype=torch.float)

Target = torch.tensor ([0,1,1], dtype=torch.long)

Weights = torch.tensor ([1,2])

Weighted cross entropy Lossimport torchimport torch.nn as nninputs = torch.tensor ([[1,2], [1,3], [1,3]], dtype=torch.float) target = torch.tensor ([0,1,1], dtype=torch.long) # def loss functionweights = torch.tensor ([1,200], dtype=torch.float) loss_f_none_w = nn.CrossEntropyLoss (weight=weights, reduction='none') loss_f_sum = nn.CrossEntropyLoss (weight=weights, reduction='sum') loss_f_mean = nn.CrossEntropyLoss (weight=weights) Reduction='mean') # forwardloss_none_w = loss_f_none_w (inputs, target) loss_sum = loss_f_sum (inputs, target) loss_mean = loss_f_mean (inputs, target) # viewprint ("\ nweights:", weights) print (loss_none_w, loss_sum, loss_mean) Thank you for your reading The above is the content of "what is the role of PyTorch reduction". After the study of this article, I believe you have a deeper understanding of what the role of PyTorch reduction is, and the specific use needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Function learning content pattern function parameter that is train of thought situation loss article more knowledge knowledge point article follow question cross practice push Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft macOS Huawei Shulou Technology