import argparse parser = argparse.ArgumentParser(description='Compare trained model with random and perfect AI') parser.add_argument('--path', metavar='N', type=str, nargs='?', default=None, help='working path') parser.add_argument('--count', metavar='N', type=int, nargs='?', default=None, help='compare count') args = parser.parse_args() arg_dict = vars(args) if arg_dict['path'] == None: scan_dir = os.path.join('output',MY_NAME) filename_list = os.listdir(scan_dir) if len(filename_list) <= 0: raise '{} is empty'.format(scan_dir) filename_int_list = [util.to_int(filename,-1) for filename in filename_list] arg_timestamp = str(max(filename_int_list)) arg_dict['path'] = os.path.join(scan_dir,str(arg_timestamp)) if arg_dict['count'] == None: arg_dict['count'] = 0 while os.path.isfile(os.path.join(os.path.join(arg_dict['path'],'deeplearn','sess','{}.index'.format((arg_dict['count']+1)*1000)))): arg_dict['count'] += 1 logging.info('QLCMICZK arg_dict {}'.format(json.dumps(arg_dict))) with open(os.path.join(arg_dict['path'],'deeplearn','input_arg_dict.json'),'r') as deeplearn_arg_dict_file: deeplearn_arg_dict = json.load(deeplearn_arg_dict_file) vs_dict_meta_list = [ {
metavar='N', type=int, nargs='?', default=None, help='compare filename') args = parser.parse_args() arg_dict = vars(args) if arg_dict['filename'] == None: dlcompare_path = os.path.join('output', MY_NAME, 'dlcompare') filename_list = os.listdir(dlcompare_path) if len(filename_list) <= 0: raise '{} is empty'.format(dlcompare_path) filename_int_list = [ myutil.to_int(filename[:-5], -1) for filename in filename_list if filename.endswith('.json') ] arg_dict['filename'] = os.path.join( dlcompare_path, '{}.json'.format(max(filename_int_list))) data_dict = {} with open(arg_dict['filename'], 'r') as in_file: result_list = json.load(in_file) win_key_list = [ { 'type': 'win', 'name': 'pd', 'win': 'X', 'style': 'ro'
if __name__ == '__main__': parser = argparse.ArgumentParser(description='Show graph') parser.add_argument('filename', metavar='N', type=int, nargs='?', default=None, help='compare filename') args = parser.parse_args() arg_dict = vars(args) if arg_dict['filename'] == None: dl_path = os.path.join('output',MY_NAME) dl_filename_list = os.listdir(dl_path) if len(dl_filename_list) <= 0: raise '{} is empty'.format(dl_path) dl_filename_int_list = [myutil.to_int(filename,-1) for filename in dl_filename_list] dl_filename_int = max(dl_filename_int_list) dc_path = os.path.join(dl_path,str(dl_filename_int),'dlcompare') dc_filename_list = os.listdir(dc_path) dc_filename_int_list = [myutil.to_int(filename[:-5],-1) for filename in dc_filename_list if filename.endswith('.json')] dc_filename_int = max(dc_filename_int_list) arg_dict['filename'] = os.path.join(dc_path,'{}.json'.format(dc_filename_int)) data_dict = {} with open(arg_dict['filename'],'r') as in_file: result_list = json.load(in_file) itr_count = 0 for result in result_list: if not 'itr' in result['input']:
def main(_): argparser = argparse.ArgumentParser() argparser.add_argument( '--output_path', type=str, help='The path to which checkpoints and other outputs ' 'should be saved. This can be either a local or GCS ' 'path.', default=None ) argparser.add_argument( '--random_stddev', type=float, help='random_stddev', default=0.1 ) argparser.add_argument( '--random_move_chance', type=float, help='RANDOM_MOVE_CHANCE', default=0.05 ) argparser.add_argument( '--train_beta', type=float, help='TRAIN_BETA', default=0.99 ) argparser.add_argument( '--turn_count', type=int, help='turn_count', default=None ) argparser.add_argument( '--device', type=str, help='device', default=None ) argparser.add_argument( '--continue', action='store_true', help='continue' ) # argparser.add_argument( # '--element_l2_factor', # type=float, # help='ELEMENT_L2_FACTOR', # default=10.0 # ) # argparser.add_argument( # '--l2_weight', # type=float, # help='L2_WEIGHT', # default=0.1 # ) argparser.add_argument( '--train_memory', type=int, help='TRAIN_MEMORY', default=10000 ) argparser.add_argument( '--dropout_keep_prob', type=float, help='dropout_keep_prob', default=0.5 ) args, _ = argparser.parse_known_args() arg_dict = vars(args) logging.info('YGYMBFMN arg_dict {}'.format(json.dumps(arg_dict))) if(arg_dict['output_path']==None): if not arg_dict['continue']: timestamp = int(time.time()) arg_dict['output_path'] = os.path.join('output',MY_NAME,str(timestamp),'deeplearn') else: filename_list = os.listdir(os.path.join('output',MY_NAME)) filename_int_list = [util.to_int(filename,-1) for filename in filename_list] arg_timestamp = str(max(filename_int_list)) arg_dict['output_path'] = os.path.join('output',MY_NAME,str(arg_timestamp),'deeplearn') if arg_dict['continue']: with open(os.path.join(arg_dict['output_path'],'input_arg_dict.json'),'r') as deeplearn_arg_dict_file: deeplearn_arg_dict = json.load(deeplearn_arg_dict_file) arg_dict = deeplearn_arg_dict arg_dict['continue'] = True else: py23.makedirs(arg_dict['output_path'],exist_ok=True) with open(os.path.join(arg_dict['output_path'],'input_arg_dict.json'),'w') as out_file: json.dump(arg_dict,out_file) with tf.device(arg_dict['device']): # with tf.device('/gpu:0'): game = Game() dl = DeepLearn(arg_dict) po = DLPlayer(dl) po.set_side(tttl.Pid.O) px = DLPlayer(dl) px.set_side(tttl.Pid.X) game.setPlayer(tttl.Pid.O, po) game.setPlayer(tttl.Pid.X, px) game.run(turn_count=arg_dict['turn_count'],p=logging.debug)
def main(_): argparser = argparse.ArgumentParser() argparser.add_argument( '--output_path', type=str, help='The path to which checkpoints and other outputs ' 'should be saved. This can be either a local or GCS ' 'path.', default=None ) argparser.add_argument( '--random_stddev', type=float, help='random_stddev', default=0.1 ) argparser.add_argument( '--random_move_chance', type=float, help='RANDOM_MOVE_CHANCE', default=0.05 ) argparser.add_argument( '--train_beta', type=float, help='TRAIN_BETA', default=0.99 ) argparser.add_argument( '--turn_count', type=int, help='turn_count', default=None ) argparser.add_argument( '--device', type=str, help='device', default=None ) argparser.add_argument( '--continue', action='store_true', help='continue' ) # argparser.add_argument( # '--element_l2_factor', # type=float, # help='ELEMENT_L2_FACTOR', # default=10.0 # ) # argparser.add_argument( # '--l2_weight', # type=float, # help='L2_WEIGHT', # default=0.1 # ) argparser.add_argument( '--train_memory', type=int, help='TRAIN_MEMORY', default=10000 ) args, _ = argparser.parse_known_args() arg_dict = vars(args) logging.info('YGYMBFMN arg_dict {}'.format(json.dumps(arg_dict))) if(arg_dict['output_path']==None): if not arg_dict['continue']: timestamp = int(time.time()) arg_dict['output_path'] = os.path.join('output',MY_NAME,str(timestamp),'deeplearn') else: filename_list = os.listdir(os.path.join('output',MY_NAME)) filename_int_list = [util.to_int(filename,-1) for filename in filename_list] arg_timestamp = str(max(filename_int_list)) arg_dict['output_path'] = os.path.join('output',MY_NAME,str(arg_timestamp),'deeplearn') if arg_dict['continue']: with open(os.path.join(arg_dict['output_path'],'input_arg_dict.json'),'r') as deeplearn_arg_dict_file: deeplearn_arg_dict = json.load(deeplearn_arg_dict_file) arg_dict = deeplearn_arg_dict arg_dict['continue'] = True else: py23.makedirs(arg_dict['output_path'],exist_ok=True) with open(os.path.join(arg_dict['output_path'],'input_arg_dict.json'),'w') as out_file: json.dump(arg_dict,out_file) with tf.device(arg_dict['device']): # with tf.device('/gpu:0'): game = Game() dl = DeepLearn(arg_dict) po = DLPlayer(dl) po.set_side(tttl.Pid.O) px = DLPlayer(dl) px.set_side(tttl.Pid.X) game.setPlayer(tttl.Pid.O, po) game.setPlayer(tttl.Pid.X, px) game.run(turn_count=arg_dict['turn_count'],p=logging.debug)
type=int, nargs='?', default=None, help='compare filename') args = parser.parse_args() arg_dict = vars(args) if arg_dict['filename'] == None: dl_path = os.path.join('output', MY_NAME) dl_filename_list = os.listdir(dl_path) if len(dl_filename_list) <= 0: raise '{} is empty'.format(dl_path) dl_filename_int_list = [ myutil.to_int(filename, -1) for filename in dl_filename_list ] dl_filename_int = max(dl_filename_int_list) dc_path = os.path.join(dl_path, str(dl_filename_int), 'dlcompare') dc_filename_list = os.listdir(dc_path) dc_filename_int_list = [ myutil.to_int(filename[:-5], -1) for filename in dc_filename_list if filename.endswith('.json') ] dc_filename_int = max(dc_filename_int_list) arg_dict['filename'] = os.path.join(dc_path, '{}.json'.format(dc_filename_int)) data_dict = {} with open(arg_dict['filename'], 'r') as in_file:
metavar='N', type=int, nargs='?', default=None, help='compare count') args = parser.parse_args() arg_dict = vars(args) if arg_dict['path'] == None: scan_dir = os.path.join('output', MY_NAME) filename_list = os.listdir(scan_dir) if len(filename_list) <= 0: raise '{} is empty'.format(scan_dir) filename_int_list = [ util.to_int(filename, -1) for filename in filename_list ] arg_timestamp = str(max(filename_int_list)) arg_dict['path'] = os.path.join(scan_dir, str(arg_timestamp)) if arg_dict['count'] == None: arg_dict['count'] = 0 while os.path.isfile( os.path.join( os.path.join( arg_dict['path'], 'deeplearn', 'sess', '{}.index'.format((arg_dict['count'] + 1) * 1000)))): arg_dict['count'] += 1 logging.info('QLCMICZK arg_dict {}'.format(json.dumps(arg_dict)))