Exemple #1
0
def parse_sgf_to_examples(sgf_path):
    """Return supervised examples from positions

    NOTE: last move is not played because no p.next_move after.
    """

    return zip(*[(p.position, p.next_move, p.result)
                 for p in sgf_wrapper.replay_sgf_file(sgf_path)])
Exemple #2
0
def make_dataset_from_sgf(board_size, sgf_filename, tf_record):
    pwcs = sgf_wrapper.replay_sgf_file(board_size, sgf_filename)

    def make_tf_example_from_pwc(pwcs):
        return _make_tf_example_from_pwc(board_size, pwcs)

    tf_examples = map(make_tf_example_from_pwc, pwcs)
    write_tf_examples(tf_record, tf_examples)
def main(argv):
    network = dual_net.DualNetwork('minigo-models/models/000737-fury')		# add path to model

    board = np.zeros([N, N], dtype=np.int8)

    pos_w_con = list(replay_sgf_file('go_puzzles/10458/10494.sgf')) # Loading a puzzle from go_puzzles folder 
    board += pos_w_con[0].position.board # Setting up the board
    
	# Let's add new pieces from another puzzle
    pos_w_con = list(replay_sgf_file('go_puzzles/14511/14515.sgf'))
    board += pos_w_con[0].position.board
	
	# Load the board position
    pos = Position(board = board)
    print(pos)
	
	# Generate saliency maps, see results folder
    play_network(network, board)
Exemple #4
0
def main(argv):
    features, labels = dual_net.get_inference_input()
    tf_tensors = dual_net.model_inference_fn(features, False)
    if len(tf_tensors) != 4:
        print("oneoffs/embeddings.py requires you modify")
        print("dual_net.model_inference_fn and add a fourth param")
        sys.exit(1)

    p_out, v_out, logits, shared = tf_tensors
    predictions = {'shared': shared}

    sess = tf.Session()
    tf.train.Saver().restore(sess, FLAGS.model)

    try:
        progress = tqdm(get_files())
        embeddings = []
        metadata = []
        for i, f in enumerate(progress):
            short_f = os.path.basename(f)
            short_f = short_f.replace('minigo-cc-evaluator', '')
            short_f = short_f.replace('-000', '-')
            progress.set_description('Processing %s' % short_f)

            processed = []
            for idx, p in enumerate(sgf_wrapper.replay_sgf_file(f)):
                if idx < FLAGS.first: continue
                if idx > FLAGS.last: break
                if idx % FLAGS.every != 0: continue

                processed.append(features_lib.extract_features(p.position))
                metadata.append((f, idx))

            if len(processed) > 0:
                # If len(processed) gets too large may have to chunk.
                res = sess.run(predictions, feed_dict={features: processed})
                for r in res['shared']:
                    embeddings.append(r.flatten())
    except:
        # Raise shows us the error but only after the finally block executes.
        raise
    finally:
        with open(FLAGS.embedding_file, 'wb') as pickle_file:
            pickle.dump([metadata, np.array(embeddings)], pickle_file)
Exemple #5
0
def make_dataset_from_sgf(sgf_filename, tf_record):
    pwcs = sgf_wrapper.replay_sgf_file(sgf_filename)
    tf_examples = map(_make_tf_example_from_pwc, pwcs)
    write_tf_examples(tf_record, tf_examples)
Exemple #6
0
def final_position_sgf(sgf_path):
    for pwc in sgf_wrapper.replay_sgf_file(sgf_path):
        pass

    return pwc.position.play_move(pwc.next_move)
Exemple #7
0
def main(argv):
    network = dual_net.DualNetwork(
        'minigo-models/models/000737-fury')  # add path to model

    board = np.zeros([N, N], dtype=np.int8)
    # pos_w_con = list(replay_sgf_file('go_puzzles/14511/14511.sgf'))

    # pos_w_con = list(replay_sgf_file('go_puzzles/10/10.sgf'))
    # board += pos_w_con[0].position.board

    # pos_w_con = list(replay_sgf_file('go_puzzles/9225/9225.sgf'))
    # board += pos_w_con[0].position.board

    # pos_w_con = list(replay_sgf_file('go_puzzles/14571/14587.sgf'))
    # board += pos_w_con[0].position.board

    # pos_w_con = list(replay_sgf_file('go_puzzles/14054/14064.sgf'))
    # board += pos_w_con[0].position.board

    # pos_w_con = list(replay_sgf_file('go_puzzles/10458/7592.sgf'))
    # board += pos_w_con[0].position.board

    # pos_w_con = list(replay_sgf_file('go_puzzles/10458/10458.sgf'))
    # board += pos_w_con[0].position.board

    # pos_w_con = list(replay_sgf_file('go_puzzles/10458/10495.sgf'))
    # board += pos_w_con[0].position.board

    pos_w_con = list(replay_sgf_file('go_puzzles/10458/10494.sgf'))
    board += pos_w_con[0].position.board

    # pos_w_con = list(replay_sgf_file('go_puzzles/10458/7593.sgf'))
    # board += pos_w_con[0].position.board

    pos_w_con = list(replay_sgf_file('go_puzzles/14511/14515.sgf'))
    board += pos_w_con[0].position.board

    # pos_w_con = list(replay_sgf_file('go_puzzles/10458/7589.sgf'))
    # board += pos_w_con[0].position.board

    # for i in pos_w_con:
    #     print(i.position)
    # board[5, 7] = -1
    # board[6][7] = -1
    # board[8][4:6] = -1
    # board[3][8] = -1
    # board[5][3] = -1

    # board[[11,12,13],:] = 0
    pos = Position(board=board)
    # board = board + pos_w_con[0].position.board
    # print(pos)
    # board[0][3] = -1
    # board[0][4] = 1

    # board[1][1] = -1
    # board[1][3] = -1
    # board[1][4] = 1

    # board[2][0] = -1
    # board[2, 2] = -1
    # board[2,3:5] = 1

    # board[3, 0:2] = -1
    # board[3, [2, 4]] = 1

    # board[4, 0] = -1
    # board[4, [1, 3]] = 1

    # board[5, :3] = 1

    # snap back
    # board = np.zeros([19, 19], dtype=np.int8)
    # board[0, 2] = 1
    # board[0, [5,6]] = -1
    # board[1][[1,5]] = 1
    # board[1][[2,3,4,6]] = -1
    # board[2][[0, 2,3,4,5]] = 1
    # board[[2,3], 6] = -1

    # Noise
    # board[2,-2] = 1
    # # board[4, 11] = -1
    # board[5, 15] = 1
    # board[8, 15] = -1
    # board[10, -1] = 1
    # # board[12, 10] = -1
    # # board[12, 13] = 1
    # board[17, 16] = -1

    # board[abs(board)==1] *= -1	# to invert the board colors

    pos = Position(board=board)
    print(pos)
    # simulate(network, board, steps=10)
    play_network(network, board)
Exemple #8
0
def make_dataset_from_sgf(sgf_filename, tf_record):
    pwcs = sgf_wrapper.replay_sgf_file(sgf_filename)
    tf_examples = map(_make_tf_example_from_pwc, pwcs)
    write_tf_examples(tf_record, tf_examples)