同一系列。
一,代码
import torch
import numpy as np
import matplotlib.pyplot as plt
loss = torch.nn.L1Loss(reduction='mean')
input = torch.tensor([1., 2., 3., 4.])
target = torch.tensor([4., 5., 6., 7.])
output = loss(input, target)
print(output)
loss_fn = torch.nn.MSELoss(reduction='mean')
loss = loss_fn(input, output)
print(loss)
entroy = torch.nn.CrossEntropyLoss()
input = torch.Tensor([[-0.1181, -0.3682, -0.2209]])
target = torch.tensor([0])
output = entroy(input, target)
print(output)
a = torch.tensor([1., 2., 3., 4.])
b = torch.tensor([4.1, 51., 6.1, 7.1])
similarity = torch.cosine_similarity(a, b, dim=0)
loss = 1 - similarity
print(loss)