def test_train(self): with tempfile.TemporaryDirectory() as working_dir, \ tempfile.NamedTemporaryFile() as tf_record: flags.FLAGS.model_dir = working_dir preprocessing.make_dataset_from_sgf('tests/example_game.sgf', tf_record.name) dual_net.train([tf_record.name], steps=1)
def train(working_dir): model_num, model_name = fsdb.get_latest_model() print("Training on gathered game data, initializing from {}".format(model_name)) new_model_num = model_num + 1 new_model_name = shipname.generate(new_model_num) print("New model will be {}".format(new_model_name)) training_file = os.path.join( fsdb.golden_chunk_dir(), str(new_model_num) + '.tfrecord.zz') while not gfile.Exists(training_file): print("Waiting for", training_file) time.sleep(1*60) print("Using Golden File:", training_file) try: save_file = os.path.join(fsdb.models_dir(), new_model_name) print("Training model") dual_net.train(training_file) print("Exporting model to ", save_file) dual_net.export_model(working_dir, save_file) except Exception as e: import traceback logging.error(traceback.format_exc()) print(traceback.format_exc()) logging.exception("Train error") sys.exit(1)
def train(tf_records: 'list of files of tf_records to train on', model_save_path: 'Where to export the completed generation.'): print("Training on:", tf_records[0], "to", tf_records[-1]) with utils.logged_timer("Training"): dual_net.train(*tf_records) print("== Training done. Exporting model to ", model_save_path) dual_net.export_model(flags.FLAGS.model_dir, model_save_path) freeze_graph(model_save_path)
def train(working_dir: 'tf.estimator working directory.', tf_records: 'list of files of tf_records to train on', model_save_path: 'Where to export the completed generation.'): print("Training on:", tf_records[0], "to", tf_records[-1]) with utils.logged_timer("Training"): dual_net.train(working_dir, tf_records) print("== Training done. Exporting model to ", model_save_path) dual_net.export_model(working_dir, model_save_path) freeze_graph(model_save_path)
def train( working_dir: 'tf.estimator working directory.', tf_records: 'list of files of tf_records to train on', model_save_path: 'Where to export the completed generation.', generation_num: 'Which generation you are training.'=0): print("Training on:", tf_records[0], "to", tf_records[-1]) with timer("Training"): dual_net.train(working_dir, tf_records, generation_num) dual_net.export_model(working_dir, model_save_path) freeze_graph(model_save_path)
def train(working_dir: 'tf.estimator working directory.', chunk_dir: 'Directory where gathered training chunks are.', model_save_path: 'Where to export the completed generation.', generation_num: 'Which generation you are training.' = 0): tf_records = sorted(gfile.Glob(os.path.join(chunk_dir, '*.tfrecord.zz'))) tf_records = tf_records[-1 * (WINDOW_SIZE // EXAMPLES_PER_RECORD):] print("Training from:", tf_records[0], "to", tf_records[-1]) with timer("Training"): dual_net.train(working_dir, tf_records, generation_num) dual_net.export_model(working_dir, model_save_path)
def train( working_dir: 'tf.estimator working directory.', chunk_dir: 'Directory where gathered training chunks are.', model_save_path: 'Where to export the completed generation.', generation_num: 'Which generation you are training.'=0): tf_records = sorted(gfile.Glob(os.path.join(chunk_dir, '*.tfrecord.zz'))) tf_records = tf_records[-1 * (WINDOW_SIZE // EXAMPLES_PER_RECORD):] print("Training from:", tf_records[0], "to", tf_records[-1]) with timer("Training"): dual_net.train(working_dir, tf_records, generation_num) dual_net.export_model(working_dir, model_save_path)
def test_train(self): with tempfile.TemporaryDirectory() as working_dir, \ tempfile.NamedTemporaryFile() as tf_record: preprocessing.make_dataset_from_sgf('tests/example_game.sgf', tf_record.name) dual_net.train(working_dir, [tf_record.name], 1, **fast_hparams)
def test_train(self): with tempfile.TemporaryDirectory() as working_dir, \ tempfile.NamedTemporaryFile() as tf_record: preprocessing.make_dataset_from_sgf( 'tests/example_game.sgf', tf_record.name) dual_net.train(working_dir, [tf_record.name], 1, **fast_hparams)