torchood 使用文档

2024-12-16技术python 我的开源作品 技术文档

前言

这个项目最早源于我对 OOD 一类方法在医学图像分类任务上的探索,下面是这个过程中诞生的一篇博客。

EDL(Evidential Deep Learning) 原理与代码实现
OOD 指这么一类任务 ...

支持的模型

支持的模型来源
Robust Classification with Convolutional Prototype Learning (Prototype Networks)CVPR 2018: Rbust classification with convolutional prototype learningopen in new window
Predictive Uncertainty Estimation via Prior Networks(Prior Networks)NeurIPS 2018: Predictive Uncertainty Estimation via Prior Networks
Evidential Deep Learning to Quantify Classification Uncertainty (EDL)NeurIPS 2018: Evidential Deep Learning to Quantify Classification Uncertaintyopen in new window
Posterior Network (PostNet)NeurIPS 2020: Posterior Network: Uncertainty Estimation without OOD Samples via Density-Based Pseudo-Counts
Evidential Neural Network (ENN)NeurIPS 2018: Evidential Deep Learning to Quantify Classification Uncertaintyopen in new window
Evidence Reconciled Neural Network(ERNN)MICCAI 2023: Evidence Reconciled Neural Network for Out-of-Distribution Detection in Medical Imagesopen in new window
Redundancy Removing Evidential Neural Network(R2ENN)-

使用方法

安装

pip install torchood

将分类器模型转换为能够输出不确定度的模型

import torchood

class UserDefineModel(nn.Module):
    ...

classifier = UserDefineModel(...)
classifier = torchood.EvidenceNeuralNetwork(classifier)

训练

for data, label in train_loader:
    # 将 data & label 转换到对应的 device 上面
    # ...

    _, evidence, _ = classifier(data)
    loss = classifier.criterion(evidence, label)

    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

推理

prob, uncertainty = classifier.predict(inputs)

INFO

uncertainty 可以作为系统的拒答流的响应阈值进行使用.


实践场景

下面罗列使用了这套方法的项目:

LSTM-Kirigaya/Lagrange.RagBot
基于 ENN 的客服机器人
Last Updated 2024-12-16 11:18:59