我正在使用 pytorch-lightning 训练变分自动编码器。我的 pytorch-lightning 代码与权重和偏差记录器一起使用。我正在尝试使用 W&B 参数扫描进行参数扫描。
超参数搜索过程基于我从这个 repo 中遵循的内容。
运行正确初始化,但是当我的训练脚本使用第一组超参数运行时,我收到以下错误:
2020-08-14 14:09:07,109 - wandb.wandb_agent - INFO - About to run command: /usr/bin/env python train_sweep.py --LR=0.02537477586974176
Traceback (most recent call last):
File "train_sweep.py", line 1, in <module>
import yaml
ImportError: No module named yaml
yaml
已安装并且工作正常。我可以通过手动设置参数来训练网络,但不能使用参数扫描。
这是我训练 VAE 的扫描脚本:
import yaml
import numpy as np
import ipdb
import torch
from vae_experiment import VAEXperiment
import torch.backends.cudnn as cudnn
from pytorch_lightning import Trainer
from pytorch_lightning.loggers import WandbLogger
from pytorch_lightning.callbacks import EarlyStopping
from vae_network import VanillaVAE
import os
import wandb
from utils import get_config, log_to_wandb
# Sweep parameters
hyperparameter_defaults = dict(
root='data_semantics',
gpus=1,
batch_size = 2,
lr = 1e-3,
num_layers = 5,
features_start = 64,
bilinear = False,
grad_batches = 1,
epochs = 20
)
wandb.init(config=hyperparameter_defaults)
config = wandb.config
def main(hparams):
model = VanillaVAE(hparams['exp_params']['img_size'], **hparams['model_params'])
model.build_layers()
experiment = VAEXperiment(model, hparams['exp_params'], hparams['parameters'])
logger = WandbLogger(
project='vae',
name=config['logging_params']['name'],
version=config['logging_params']['version'],
save_dir=config['logging_params']['save_dir']
)
wandb_logger.watch(model.net)
early_stopping = EarlyStopping(
monitor='val_loss',
min_delta=0.00,
patience=3,
verbose=False,
mode='min'
)
runner = Trainer(weights_save_path="../../Logs/",
min_epochs=1,
logger=logger,
log_save_interval=10,
train_percent_check=1.,
val_percent_check=1.,
num_sanity_val_steps=5,
early_stop_callback = early_stopping,
**config['trainer_params']
)
runner.fit(experiment)
if __name__ == '__main__':
main(config)
为什么我会收到此错误?