python - Pytorch模型的超参数优化

标签 python machine-learning deep-learning pytorch hyperparameters

对 Pytorch 模型执行超参数优化的最佳方法是什么?实现例如随机搜索我自己?使用 Skicit Learn 吗?还是还有什么我不知道的?

最佳答案

许多研究人员使用RayTune 。它是一个可扩展的超参数调整框架,专门用于深度学习。您可以轻松地将它与任何深度学习框架(下面 2 行代码)一起使用,并且它提供了最先进的算法,包括 HyperBand、基于群体的训练、贝叶斯优化和 BOHB。

import torch.optim as optim
from ray import tune
from ray.tune.examples.mnist_pytorch import get_data_loaders, ConvNet, train, test


def train_mnist(config):
    train_loader, test_loader = get_data_loaders()
    model = ConvNet()
    optimizer = optim.SGD(model.parameters(), lr=config["lr"])
    for i in range(10):
        train(model, optimizer, train_loader)
        acc = test(model, test_loader)
        tune.report(mean_accuracy=acc)


analysis = tune.run(
    train_mnist, config={"lr": tune.grid_search([0.001, 0.01, 0.1])})

print("Best config: ", analysis.get_best_config(metric="mean_accuracy"))

# Get a dataframe for analyzing trial results.
df = analysis.dataframe()

[免责声明:我积极为这个项目做出贡献!]

关于python - Pytorch模型的超参数优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44260217/

相关文章:

python - 在 pymongo 中使用 $natural sort - MongoDB

python - Tensorflow:保存/恢复变量加载不正确

python - 通过全批量训练将字母图像训练到神经网络

python - 从 Lambda 到 SNS 到 SQS 到另一个 Lambda 的 AWS X-Ray 跟踪(Python3、boto3)

python - 'import cv' 之后的 `Fatal Python error: PyThreadState_Get: no current thread`

image-processing - 使用反向传播训练 CNN

python - 如何在 YOLO v8 中卡住主干、特征提取层

c++ - 在 Caffe 中保存输出图像

python - 无法让我的删除按钮链接显示在 Django 中

python - 如何以概率输出 Shap 值并从二元分类器制作 force_plot