loss functions

一些常见的损失函数调包就行,复杂的得自己写。损失函数中没有可训练的参数,因此通常直接使用torch.nn.functional中的函数即可。例如一些简单的损失函数:

1
2
3
4
import torch.nn as nn
cls_criterion = nn.CrossEntropyLoss()
dist_criterion = nn.MSELoss() # Use L2 loss function
hinge_criterion = nn.HingeEmbeddingLoss()

还可以参照pytorch-metric-learning这个库

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×