Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

update selfplay to write 5% of games to a holdout directory #57

Merged
merged 2 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def evaluate(
def selfplay(
load_file: "The path to the network model files",
output_dir: "Where to write the games"="data/selfplay",
holdout_dir: "Where to write the games"="data/holdout",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this written to local disk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's written to wherever you pass it. This can be a gs:// path

output_sgf: "Where to write the sgfs"="sgf/",
readouts: 'How many simulations to run per move'=100,
verbose: '>=2 will print debug info, >=3 will print boards' = 1,
Expand All @@ -138,8 +139,15 @@ def selfplay(
with gfile.GFile(os.path.join(output_sgf, '{}.sgf'.format(output_name)), 'w') as f:
f.write(player.to_sgf())

fname = os.path.join(output_dir, "{}.tfrecord.zz".format(output_name))
preprocessing.make_dataset_from_selfplay(game_data, fname)
tf_examples = preprocessing.make_dataset_from_selfplay(game_data)

# Hold out 5% of games for evaluation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make 0.05 a flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gilding the lily a bit but done :)

if random.random() < 0.05:
fname = os.path.join(holdout_dir, "{}.tfrecord.zz".format(output_name))
else:
fname = os.path.join(output_dir, "{}.tfrecord.zz".format(output_name))

preprocessing.write_tf_examples(fname, tf_examples)


def gather(
Expand Down
6 changes: 3 additions & 3 deletions preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ def get_input_tensors(batch_size, tf_records, num_repeats=None,
# End-to-end utility functions


def make_dataset_from_selfplay(data_extracts, tf_record):
def make_dataset_from_selfplay(data_extracts):
'''
Returns a set of tf.Examples.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return an iterable of tf.Example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Args:
data_extracts: An iterable of (position, pi, result) tuples
tf_record: name of file to write to
'''
tf_examples = (make_tf_example(features_lib.extract_features(pos), pi, result)
for pos, pi, result in data_extracts)
write_tf_examples(tf_record, tf_examples)
return tf_examples


def make_dataset_from_sgf(sgf_filename, tf_record):
Expand Down
2 changes: 2 additions & 0 deletions rl_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
BASE_DIR = "gs://{}".format(BUCKET_NAME)
MODELS_DIR = os.path.join(BASE_DIR, 'models')
SELFPLAY_DIR = os.path.join(BASE_DIR, 'games')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're rejiggering our folder naming scheme, can we rename the selfplay dir? "games" is pretty nondescriptive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

HOLDOUT_DIR = os.path.join(BASE_DIR, 'holdout')
SGF_DIR = os.path.join(BASE_DIR, 'sgf')
TRAINING_CHUNK_DIR = os.path.join(BASE_DIR, 'data', 'training_chunks')

Expand Down Expand Up @@ -88,6 +89,7 @@ def selfplay(readouts=1600, verbose=2, resign_threshold=0.99):
main.selfplay(
load_file=model_save_file,
output_dir=os.path.join(SELFPLAY_DIR, model_name),
holdout_dir=os.path.join(HOLDOUT_DIR, model_name),
output_sgf=SGF_DIR,
readouts=readouts,
verbose=verbose,
Expand Down