jos*_*ks7 1 python config artificial-intelligence attributeerror neural-network
我正在浏览使用此处找到的 NEAT 神经网络 API 播放飞扬小鸟的 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'
Run Code Online (Sandbox Code Playgroud)
问题似乎来自这段代码:
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)
Run Code Online (Sandbox Code Playgroud)
但是,我查看了此处找到的 Neat 文档,它说该属性确实存在。如果相关,我将在 Mac 上使用 Pycharm。有谁知道错误来自哪里?
我遇到过同样的问题。当我在安装了neat-python而不是通过pip运行后运行相同的代码时,我的问题得到了解决。所以尝试这样做
pip安装整洁的python
还要确保requirements.txt 中给出的所有包都已经存在于您的PC 中。