【发布时间】:2020-02-22 18:15:57
【问题描述】:
我正在浏览使用找到的 NEAT 神经网络 API here 的 AI 玩飞扬小鸟的指南。
当我运行他从 Github 下载的代码时,它给了我错误:
"Traceback (most recent call last):
File "test.py", line 438, in <module>
run(config_path)
File "test.py", line 412, in run
config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction,
AttributeError: module 'neat' has no attribute 'config'
问题似乎来自这段代码:
def run(config_file):
"""
runs the NEAT algorithm to train a neural network to play flappy bird.
:param config_file: location of config file
:return: None
"""
config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_file)
# Create the population, which is the top-level object for a NEAT run.
p = neat.Population(config)
# Add a stdout reporter to show progress in the terminal.
p.add_reporter(neat.StdOutReporter(True))
stats = neat.StatisticsReporter()
p.add_reporter(stats)
#p.add_reporter(neat.Checkpointer(5))
# Run for up to 50 generations.
winner = p.run(eval_genomes, 50)
# show final stats
print('\nBest genome:\n{!s}'.format(winner))
if __name__ == '__main__':
# Determine path to configuration file. This path manipulation is
# here so that the script will run successfully regardless of the
# current working directory.
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'config-feedforward.txt')
run(config_path)
但是,我查看了 Neat 文档,发现 here,它说这个属性确实存在。如果相关的话,我在 Mac 上使用 Pycharm。有谁知道错误来自哪里?
【问题讨论】:
-
如果你运行
import neat; print(neat.__file__)会发生什么? -
这个文件中的导入到底是什么(
def run(...)之前)?有import neat,还是import neat.config? -
@mkrieger1 至于我在终端中运行的第一个问题,它给了我“//anaconda3/lib/python3.7/site-packages/neat/__init__.py”
-
@mkrieger1 对于第二个问题,我只导入了整洁,而不是导入整洁.config,但我尝试了整洁.config 和整洁.Config,但似乎都不起作用
-
当你尝试使用
import neat.config时发生了什么?
标签: python neural-network artificial-intelligence config attributeerror