def subsample():
    """Sample num_positions postions from each game in sgf_dir

    Usage:
        python3 sharp_positions.py subsample --num_positions 10 --sgf_dir data/s

    NOTE(sethtroisi): see link for a script to truncate SGFs at move number
        https://github.com/sethtroisi/go-scripts
    """

    sgf_files = oneoff_utils.find_and_filter_sgf_files(
        FLAGS.sgf_dir, None, None)

    with open(FLAG.collection, 'w') as collection:
        fails = 0
        for path in tqdm(sorted(sgf_files)):
            try:
                positions, moves, results = oneoff_utils.parse_sgf(path)
            except KeyboardInterrupt:
                raise
            except Exception as e:
                fails += 1
                print("Fail {}, while parsing {}: {}".format(fails, path, e))
                continue

            moves = len(positions)
            indexes = random.sample(range(10, moves), FLAGS.num_positions)
            for index in sorted(indexes):
                collection.write('{}, {}\n'.format(path, index))
def subsample ( ) : sgf_files = oneoff_utils . find_and_filter_sgf_files ( FLAGS . sgf_dir , None , None ) with open ( FLAG . collection , 'w' ) as collection : fails = 0 for path in tqdm ( sorted ( sgf_files ) ) : try : positions , moves , results = oneoff_utils . parse_sgf ( path ) except KeyboardInterrupt : raise except Exception as e : fails += 1 print ( "Fail {}, while parsing {}: {}" . format ( fails , path , e ) ) continue moves = len ( positions ) indexes = random . sample ( range ( 10 , moves ) , FLAGS . num_positions ) for index in sorted ( indexes ) : collection . write ( '{}, {}\n' . format ( path , index ) )
Sample num_positions postions from each game in sgf_dir

    Usage:
        python3 sharp_positions.py subsample --num_positions 10 --sgf_dir data/s

    NOTE(sethtroisi): see link for a script to truncate SGFs at move number
        https://github.com/sethtroisi/go-scripts