[英]How do i save and retrain a neat-python model?
我训练了一个整洁的蟒蛇 model 来玩贪吃蛇。 我想在 50 代之后保存 model,然后我想加载它并从那里重新训练它,这可能吗? 我看到了一种可以重放的方法,但只需重放一次,而不是从那个阶段重新训练它。
我的保存代码:
winner = p.run(main, 170)
with open("winner.pkl", "wb") as f:
pickle.dump(winner, f)
f.close()
我希望能够加载它并再次调用运行 function 来重新训练它
def run(config_file):
config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction,
neat.DefaultSpeciesSet, neat.DefaultStagnation,
config_file)
p = neat.Population(config)
p.add_reporter(neat.StdOutReporter(True))
stats = neat.StatisticsReporter()
p.add_reporter(stats)
winner = p.run(main, 50)
with open("winner.pkl", "wb") as f:
pickle.dump(winner, f)
f.close()
if __name__ == '__main__':
local_dir = os.path.dirname(__file__)
config_path = os.path.join(local_dir, 'config-feedforward.txt')
run(config_path)
试试这个:
https://neat-python.readthedocs.io/en/latest/_modules/checkpoint.html
它有效,唯一的问题是它从上次保存的一代加载并再次覆盖它。
所以如果你运行5代并且保存所有5个:0,1,2,3,4; 如果你加载最后一个,你将获得保存:4,5,6,7,8
这不允许只保存一代,因为它会加载并重做同一代,这基本上会让你一直处于第 0 代.. 超级奇怪。
但如果你不介意每次都失去你的上一代,这就是剧本。
有人对此有解决方法吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.