Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Assignment 1 - All About torch.Tensor
Deep Learning with PyTorch: Zero to GANs
PyTorch is an open source machine learning library written in Python and C++. PyTorch is a favorite among researchers because it allows for quick prototyping and has a simple API.
Loss function is a mathematical optimization function. Loss functions are located in torch.nn module in the Pytorch library. Some of the loss functions are as follows:
- torch.nn.L1Loss
- torch.nn.MSELoss
- torch.nn.NLLLoss
- torch.nn.CrossEntropyLoss
- torch.nn.KLDivLoss
# Import torch and other required modules
import torch
import torch.nn as nn
Function 1 - torch.nn.L1Loss
the mean absolute error is measured
# Example 1 -
loss = nn.L1Loss()
pred = torch.tensor(4.)
target = torch.tensor(5.)
output = loss(pred, target)
output
tensor(1.)
Explanation about example: loss(4.,5.)=|4.-5.|=|-1.|=1.