8000 minigo/preprocessing.py at master · kevinwangl/minigo · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
207 lines (177 loc) · 7.03 KB

preprocessing.py

File metadata and controls

207 lines (177 loc) · 7.03 KB
'''
tf_examples = (make_tf_example(features_lib.extract_features(pos), pi, result)
for pos, pi, result in data_extracts)
return tf_examples
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)
def _make_tf_example_from_pwc(position_w_context):
features = features_lib.extract_features(position_w_context.position)
pi = _one_hot(coords.flatten_coords(position_w_context.next_move))
value = position_w_context.result
return make_tf_example(features, pi, value)
def shuffle_tf_examples(gather_size, records_to_shuffle):
'''Read through tf.Record and yield shuffled, but unparsed tf.Examples
Args:
gather_size: The number of tf.Examples to be gathered together
records_to_shuffle: A list of filenames
Returns:
An iterator yielding lists of bytes, which are serialized tf.Examples.
'''
dataset = read_tf_records(gather_size, records_to_shuffle, num_repeats=1)
batch = dataset.make_one_shot_iterator().get_next()
sess = tf.Session()
while True:
try:
result = sess.run(batch)
yield list(result)
except tf.errors.OutOfRangeError:
break
0