【亲测免费】 torch-fidelity 项目使用教程
1. 项目介绍
torch-fidelity 是一个用于生成模型评估的高保真性能指标库,专为 PyTorch 设计。它提供了精确、高效且可扩展的实现,支持多种流行的生成模型评估指标,包括 Inception Score (ISC)、Fréchet Inception Distance (FID)、Kernel Inception Distance (KID)、Precision and Recall (PRC) 以及 Perceptual Path Length (PPL)。
主要特点
- 数值精度:生成的指标值与参考实现匹配,达到浮点数的机器精度,适合在论文中报告。
- 高效性:通过特征共享和缓存机制,避免重复计算,提高评估效率。
- 可扩展性:模块化设计,易于扩展到其他类型的数据和模型。
2. 项目快速启动
安装
首先,通过 pip 安装 torch-fidelity:
pip install torch-fidelity
使用示例
以下是一个简单的示例,展示如何使用 torch-fidelity 计算 CIFAR-10 训练集的 Inception Score。
import torch_fidelity
# 计算 CIFAR-10 训练集的 Inception Score
metrics_dict = torch_fidelity.calculate_metrics(
input1='cifar10-train',
isc=True,
cuda=True,
verbose=False
)
print(metrics_dict)
输出结果将包含 Inception Score 的均值和标准差:
{
'inception_score_mean': 11.23678,
'inception_score_std': 0.09514061
}
3. 应用案例和最佳实践
案例1:评估生成模型的性能
假设你有一个生成模型 generator,你可以使用 torch-fidelity 来评估其生成的图像与 CIFAR-10 训练集之间的 FID 和 KID。
import torch_fidelity
# 假设 generator 是一个生成模型
wrapped_generator = torch_fidelity.GenerativeModelModuleWrapper(generator, 128, 'normal', 0)
metrics_dict = torch_fidelity.calculate_metrics(
input1=wrapped_generator,
input2='cifar10-train',
cuda=True,
fid=True,
kid=True,
verbose=False
)
print(metrics_dict)
案例2:在训练循环中跟踪模型性能
在训练生成模型时,可以在每个 epoch 结束时计算性能指标,以便实时监控模型的进展。
import torch_fidelity
# 假设 generator 是一个生成模型
wrapped_generator = torch_fidelity.GenerativeModelModuleWrapper(generator, 128, 'normal', 0)
for epoch in range(num_epochs):
# 训练代码...
# 计算性能指标
metrics_dict = torch_fidelity.calculate_metrics(
input1=wrapped_generator,
input2='cifar10-train',
cuda=True,
isc=True,
fid=True,
kid=True,
verbose=False
)
print(f'Epoch {epoch}: {metrics_dict}')
4. 典型生态项目
1. PyTorch
torch-fidelity 是基于 PyTorch 构建的,因此与 PyTorch 生态系统紧密集成。你可以使用 PyTorch 的模型和数据加载器来生成图像,并使用 torch-fidelity 进行评估。
2. GAN 训练框架
许多 GAN 训练框架,如 pytorch-gan 和 stylegan2-pytorch,都可以与 torch-fidelity 结合使用,以评估生成模型的性能。
3. 可视化工具
结合 TensorBoard 或 WandB 等可视化工具,可以实时监控生成模型的性能指标,帮助你更好地理解模型的训练过程。
通过这些模块的介绍和示例,你应该能够快速上手并使用 torch-fidelity 来评估生成模型的性能。
Kimi-K2.5Kimi K2.5 是一款开源的原生多模态智能体模型,它在 Kimi-K2-Base 的基础上,通过对约 15 万亿混合视觉和文本 tokens 进行持续预训练构建而成。该模型将视觉与语言理解、高级智能体能力、即时模式与思考模式,以及对话式与智能体范式无缝融合。Python00- QQwen3-Coder-Next2026年2月4日,正式发布的Qwen3-Coder-Next,一款专为编码智能体和本地开发场景设计的开源语言模型。Python00
xw-cli实现国产算力大模型零门槛部署,一键跑通 Qwen、GLM-4.7、Minimax-2.1、DeepSeek-OCR 等模型Go06
PaddleOCR-VL-1.5PaddleOCR-VL-1.5 是 PaddleOCR-VL 的新一代进阶模型,在 OmniDocBench v1.5 上实现了 94.5% 的全新 state-of-the-art 准确率。 为了严格评估模型在真实物理畸变下的鲁棒性——包括扫描伪影、倾斜、扭曲、屏幕拍摄和光照变化——我们提出了 Real5-OmniDocBench 基准测试集。实验结果表明,该增强模型在新构建的基准测试集上达到了 SOTA 性能。此外,我们通过整合印章识别和文本检测识别(text spotting)任务扩展了模型的能力,同时保持 0.9B 的超紧凑 VLM 规模,具备高效率特性。Python00
KuiklyUI基于KMP技术的高性能、全平台开发框架,具备统一代码库、极致易用性和动态灵活性。 Provide a high-performance, full-platform development framework with unified codebase, ultimate ease of use, and dynamic flexibility. 注意:本仓库为Github仓库镜像,PR或Issue请移步至Github发起,感谢支持!Kotlin07
VLOOKVLOOK™ 是优雅好用的 Typora/Markdown 主题包和增强插件。 VLOOK™ is an elegant and practical THEME PACKAGE × ENHANCEMENT PLUGIN for Typora/Markdown.Less00