使用权重和偏差扫描时无法导入模块

Unable to import modules when using Weights and Biases' sweeps

我正在尝试通过使用 weights and biases 库 (wandb) 对其进行优化来改进我的 keras 神经网络超参数。

这是我的配置:

method: bayes
metric:
  goal: maximize
  name: Search elo
parameters:
  batch_number:
    distribution: int_uniform
    max: 100
    min: 1
  batch_size:
    distribution: int_uniform
    max: 1024
    min: 1
  epochs:
    distribution: int_uniform
    max: 10
    min: 1
  neural_net_blocks:
    distribution: int_uniform
    max: 5
    min: 1
  num_simulations:
    distribution: int_uniform
    max: 800
    min: 1
  pb_c_base:
    distribution: int_uniform
    max: 25000
    min: 15000
  pb_c_init:
    distribution: uniform
    max: 3
    min: 1
  root_dirichlet_alpha:
    distribution: uniform
    max: 4
    min: 0
  root_exploration_fraction:
    distribution: uniform
    max: 1
    min: 0
program: ../Main.py

但是,当我 运行 wandb agent arkleseisure/projectname/sweepcode 时,我收到此错误,每次扫描启动时都会重复。

2020-09-13 12:15:02,188 - wandb.wandb_agent - INFO - Running runs: ['klawqpqv']
2020-09-13 12:15:02,189 - wandb.wandb_agent - INFO - Cleaning up finished run: klawqpqv
2020-09-13 12:15:03,063 - wandb.wandb_agent - INFO - Agent received command: run
2020-09-13 12:15:03,063 - wandb.wandb_agent - INFO - Agent starting run with config:
        batch_number: 75
        batch_size: 380
        epochs: 10
        neural_net_blocks: 4
        num_simulations: 301
        pb_c_base: 17138
        pb_c_init: 1.5509741790555416
        root_dirichlet_alpha: 2.7032316257955133
        root_exploration_fraction: 0.5768106739703028
2020-09-13 12:15:03,245 - wandb.wandb_agent - INFO - About to run command: python ../Main.py --batch_number=75 --batch_size=380 --epochs=10 --neural_net_blocks=4 --num_simulations=301 --p
b_c_base=17138 --pb_c_init=1.5509741790555416 --root_dirichlet_alpha=2.7032316257955133 --root_exploration_fraction=0.5768106739703028
Traceback (most recent call last):
  File "../Main.py", line 3, in <module>
    import numpy
ModuleNotFoundError: No module named 'numpy'

扫描失败三次后崩溃,我想知道我做错了什么。肯定W&B做机器学习项目的时候,肯定是可以import numpy的,我能改什么。在那之前我的代码只是从我的项目中导入其他文件。当我运行代码正常时,它没有崩溃,而是正常执行。

您 运行 遇到的最可能的问题是 wandb agent 运行 使用与您不同的 python 解释器来执行 python 脚本我们打算。

解决方案是通过在扫描配置中添加类似的内容来指定 python 解释器(其中 python3 是您希望使用的解释器):

command:
  - ${env}
  - python3
  - ${program}
  - ${args}

此功能记录在:https://docs.wandb.com/sweeps/configuration#command

关于设置 python 解释器的常见问题解答位于: https://docs.wandb.com/sweeps/faq#sweep-with-custom-commands

要进一步了解正在发生的事情,您可以查看您发布的调试行,上面写着:“关于 运行 命令:”

python ../Main.py --batch_number=75 --batch_size=380 --epochs=10 --neural_net_blocks=4 --num_simulations=301 --pb_c_base=17138 --pb_c_init=1.5509741790555416 --root_dirichlet_alpha=2.7032316257955133 --root_exploration_fraction=0.5768106739703028

默认情况下 wandb agent 使用名为 python 的 python 解释器。这允许用户自定义他们的环境,以便 python 使用 pyenv、virtualenv 或其他工具指向他们选择的解释器。

如果您通常 运行 使用 command-line python2 或 python3 命令,您可以通过指定 command 如上所述键入您的配置文件。或者,如果您的程序是可执行的,并且您的 python 解释器位于脚本的第一行,使用 #!/usr/bin/env python3 语法,您可以将命令数组设置为:

command:
  - ${env}
  - ${program}
  - ${args}