目录
Online Hard Example Mining (OHEM)损失函数:
Online Hard Example Mining (OHEM)损失函数:
OhemCrossEntropy指的是Online Hard Example Mining (OHEM) 和 Cross-Entropy Loss相结合的损失函数。这是一种在训练深度学习模型时用于处理样本不平衡和挑选困难样本的技术。
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft
# Licensed under the MIT License.
# Written by Ke Sun (sunk@mail.ustc.edu.cn)
# ------------------------------------------------------------------------------
import torch
import torch.nn as nn
from torch.nn import functional as F
import logging
from config import config
class CrossEntropy(nn.Module):
def __init__(self, ignore_label=-1, weight=None):
super(CrossEntropy, self).__init__()
self.ignore_label = ignore_label
self.criterion = nn.CrossEntropyLoss(
weight=weight,