def main(): log.info('Loading %s...', Game.__name__) g = Game(8) log.info('Loading %s...', nn.__name__) nnet = nn(g) if args.load_model: log.info('Loading checkpoint "%s/%s"...', args.load_folder_file) nnet.load_checkpoint(args.load_folder_file[0], args.load_folder_file[1]) else: log.warning('Not loading a checkpoint!') log.info('Loading the Coach...') c = Coach(g, nnet, args) if args.load_model: log.info("Loading 'trainExamples' from file...") c.loadTrainExamples() run = wandb.init(project=args.wandb_project,config=args,reinit=True) log.info('Starting the learning process 🎉') c.learn() run.finish()
from utils import * args = dotdict({ 'numIters': 1000, 'numEps': 100, 'tempThreshold': 15, 'updateThreshold': 0.6, 'maxlenOfQueue': 200000, 'numMCTSSims': 25, 'arenaCompare': 40, 'cpuct': 1, 'checkpoint': './temp/', 'load_model': False, 'load_folder_file': ('/dev/models/8x100x50', 'best.pth.tar'), 'numItersForTrainExamplesHistory': 20, }) if __name__ == "__main__": g = Game(6) nnet = nn(g) if args.load_model: nnet.load_checkpoint(args.load_folder_file[0], args.load_folder_file[1]) c = Coach(g, nnet, args) if args.load_model: print("Load trainExamples from file") c.loadTrainExamples() c.learn()
def play_previous_generations(player, folder, num_matches, game, tempThreshold, savefolder=False): # wandb.init(project="8x8 against previous iterations") wins = [] losses = [] draws = [] names = [] i = 0 generation = 0 while i <= 70: print(folder + "checkpoint_" + str(i)) if os.path.isfile(folder + "checkpoint_" + str(i)): print("loading generation " + str(generation)) network = nn(game) network.load_checkpoint(folder=folder, filename="checkpoint_" + str(i)) args = dotdict({ 'numMCTSSims': player.args.numMCTSSims, 'cpuct': player.args.cpuct }) neuralplayer = NeuralNetworkPlayer(game, network, args) neuralplayer.name = "Neural Network Generation " + str( generation) names.append(neuralplayer.name) if savefolder != False: save = savefolder + "/" + neuralplayer.name + "/" else: save = False arena = Arena(player, neuralplayer, game, tempThreshold=tempThreshold) winsG, lossesG, drawsG = arena.playGames(num_matches, save=save) wins.append(winsG) losses.append(lossesG) draws.append(drawsG) wandb.log({ 'Wins': winsG, 'Losses': lossesG, 'Draws': drawsG, 'Winrate': winsG / (winsG + drawsG + lossesG), 'Winrate including draws': (winsG + 0.5 * drawsG) / (winsG + drawsG + lossesG) }) generation = generation + 1 i = i + 1 df = pd.DataFrame(wins, columns=player.name, index=names) df2 = pd.DataFrame(wins, columns=player.name, index=names) if savefolder != False: df.to_csv(r"" + savefolder + "/wins.csv") df2.to_csv(r"" + savefolder + "/draws.csv")
'numEps': 2, #orginal value: 100 'tempThreshold': 15, 'updateThreshold': 0.6, 'maxlenOfQueue': 200000, 'numMCTSSims': 25, 'arenaCompare': 40, 'cpuct': 1, 'checkpoint': './temp/', 'load_model': False, 'load_folder_file': ('/dev/models/8x100x50', 'best.pth.tar'), 'numItersForTrainExamplesHistory': 20, }) if __name__ == "__main__": g = Game(6) #returns the game object (constructor) nnet = nn(g) #NNet class returns NNetWrapper for the game object (g) print( '----------------------********************-----------------------*********************-----------------' ) if args.load_model: nnet.load_checkpoint(args.load_folder_file[0], args.load_folder_file[1]) print('main.py==> ', 'args: ', args) c = Coach( g, nnet, args ) #returns the Coach object with params(game_object, NeuralNet, argument values) if args.load_model: print("Load trainExamples from file") c.loadTrainExamples() c.learn()