TorchEval¶
一个库,提供简单直观的模型评估工具和愉悦的用户体验。TorchEval 的高级概述:
包含丰富的开箱即用型高性能指标计算集合。我们尽可能地通过 PyTorch 利用向量化和 GPU 加速。
使用 torch.distributed 与分布式训练和工具无缝集成
设计时考虑了可扩展性:您可以自由地轻松创建自己的指标并利用我们的工具包。
提供用于分析基于 PyTorch 的模型的内存和计算需求的工具。
快速入门¶
安装¶
TorchEval 可以通过 PyPi 安装:
pip install torcheval
或从 github 安装:
git clone https://github.com/pytorch/torcheval
cd torcheval
pip install -r requirements.txt
python setup.py install
用法¶
TorchEval 为每个指标提供两种接口。如果您在单进程环境中工作,最简单的方法是使用 functional
子模块中的指标。这些指标可以在 torcheval.metrics.functional
中找到。
from torcheval.metrics.functional import binary_f1_score
predictions = model(inputs)
f1_score = binary_f1_score(predictions, targets)
我们可以在基于类的路由中使用相同的指标,它提供的工具使在多进程设置中进行计算变得简单。在单个设备上,您可以按如下方式使用基于类的指标
from torcheval.metrics import BinaryF1Score
predictions = model(inputs)
metric = BinaryF1Score()
metric.update(predictions, targets)
f1_score = metric.compute()
在多进程设置中,必须同步来自每个进程的数据才能计算整个数据集的指标。为此,只需将 metric.compute()
替换为 sync_and_compute(metric)
from torcheval.metrics import BinaryF1Score
from torcheval.metrics.toolkit import sync_and_compute
predictions = model(inputs)
metric = BinaryF1Score()
metric.update(predictions, targets)
f1_score = sync_and_compute(metric)
在分布式示例中阅读有关基于类的方法的更多信息。
进一步阅读¶
查看解释计算示例的指南
查看分布式示例
查看如何创建自己的指标