def main(unused_argv): if FLAGS.acoustic_checkpoint_filename: acoustic_checkpoint = os.path.join( os.path.expanduser(FLAGS.acoustic_run_dir), 'train', FLAGS.acoustic_checkpoint_filename) else: acoustic_checkpoint = tf.train.latest_checkpoint( os.path.join(os.path.expanduser(FLAGS.acoustic_run_dir), 'train')) run_dir = os.path.expanduser(FLAGS.run_dir) hparams = tf_utils.merge_hparams( constants.DEFAULT_HPARAMS, model.get_default_hparams()) hparams.parse(FLAGS.hparams) # Batch size should always be 1 for inference. hparams.batch_size = 1 tf.logging.info(hparams) tf.gfile.MakeDirs(run_dir) with tf.gfile.Open(os.path.join(run_dir, 'run_config.txt'), 'w') as f: f.write(acoustic_checkpoint + '\n') f.write(FLAGS.examples_path + '\n') f.write(str(hparams) + '\n') model_inference( acoustic_checkpoint=acoustic_checkpoint, hparams=hparams, examples_path=FLAGS.examples_path, run_dir=run_dir)
def main(argv): tf.logging.set_verbosity(FLAGS.log) if FLAGS.acoustic_checkpoint_filename: acoustic_checkpoint = os.path.join( os.path.expanduser(FLAGS.acoustic_run_dir), 'train', FLAGS.acoustic_checkpoint_filename) else: acoustic_checkpoint = tf.train.latest_checkpoint( os.path.join(os.path.expanduser(FLAGS.acoustic_run_dir), 'train')) hparams = tf_utils.merge_hparams(constants.DEFAULT_HPARAMS, model.get_default_hparams()) hparams.parse(FLAGS.hparams) transcription_session = initialize_session(acoustic_checkpoint, hparams) for filename in argv[1:]: tf.logging.info('Starting transcription for %s...', filename) sequence_prediction = transcribe_audio(transcription_session, filename, FLAGS.frame_threshold, FLAGS.onset_threshold) midi_filename = filename + '.midi' midi_io.sequence_proto_to_midi_file(sequence_prediction, midi_filename) tf.logging.info('Transcription written to %s.', midi_filename)
def main(argv): tf.logging.set_verbosity(FLAGS.log) if FLAGS.acoustic_checkpoint_filename: acoustic_checkpoint = os.path.join( os.path.expanduser(FLAGS.acoustic_run_dir), 'train', FLAGS.acoustic_checkpoint_filename) else: acoustic_checkpoint = tf.train.latest_checkpoint( os.path.join(os.path.expanduser(FLAGS.acoustic_run_dir), 'train')) hparams = tf_utils.merge_hparams( constants.DEFAULT_HPARAMS, model.get_default_hparams()) hparams.parse(FLAGS.hparams) transcription_session = initialize_session(acoustic_checkpoint, hparams) for filename in argv[1:]: tf.logging.info('Starting transcription for %s...', filename) sequence_prediction = transcribe_audio( transcription_session, filename, FLAGS.frame_threshold, FLAGS.onset_threshold) midi_filename = filename + '.midi' midi_io.sequence_proto_to_midi_file(sequence_prediction, midi_filename) tf.logging.info('Transcription written to %s.', midi_filename)
def main(unused_argv): tf.logging.set_verbosity(FLAGS.log) run_dir = os.path.expanduser(FLAGS.run_dir) hparams = model.get_default_hparams() # Command line flags override any of the preceding hyperparameter values. hparams.parse(FLAGS.hparams) run(hparams, run_dir)
def main(unused_argv): tf.logging.set_verbosity(FLAGS.log) run_dir = os.path.expanduser(FLAGS.run_dir) hparams = model.get_default_hparams() # Command line flags override any of the preceding hyperparameter values. hparams.parse(FLAGS.hparams) run(hparams, run_dir)
def main(unused_argv): output_dir = os.path.expanduser(FLAGS.output_dir) hparams = tf_utils.merge_hparams( constants.DEFAULT_HPARAMS, model.get_default_hparams()) hparams.parse(FLAGS.hparams) # Batch size should always be 1 for inference. hparams.batch_size = 1 tf.logging.info(hparams) tf.gfile.MakeDirs(output_dir) summary_writer = tf.summary.FileWriter(logdir=output_dir) with tf.Session(): run_config = '\n\n'.join([ 'model_dir: ' + FLAGS.model_dir, 'checkpoint_path: ' + str(FLAGS.checkpoint_path), 'examples_path: ' + FLAGS.examples_path, str(hparams), ]) run_config_summary = tf.summary.text( 'run_config', tf.constant(run_config, name='run_config'), collections=[]) summary_writer.add_summary(run_config_summary.eval()) if FLAGS.eval_loop: assert not FLAGS.checkpoint_path checkpoint_path = None while True: checkpoint_path = tf.contrib.training.wait_for_new_checkpoint( FLAGS.model_dir, last_checkpoint=checkpoint_path) model_inference( model_dir=FLAGS.model_dir, checkpoint_path=checkpoint_path, hparams=hparams, examples_path=FLAGS.examples_path, output_dir=output_dir, summary_writer=summary_writer, master=FLAGS.master, write_summary_every_step=False) else: model_inference( model_dir=FLAGS.model_dir, checkpoint_path=FLAGS.checkpoint_path, hparams=hparams, examples_path=FLAGS.examples_path, output_dir=output_dir, summary_writer=summary_writer, master=FLAGS.master)
def init(self): tf.logging.set_verbosity(self.log) acoustic_checkpoint = tf.train.latest_checkpoint( os.path.join(os.path.expanduser(self.acoustic_run_dir), 'train')) default_hparams = tf_utils.merge_hparams(constants.DEFAULT_HPARAMS, model.get_default_hparams()) default_hparams.parse(self.hparams) self.transcription_session = self.initialize_session( acoustic_checkpoint, default_hparams)
def main(unused_argv): tf.app.flags.mark_flags_as_required( ['examples_path', 'run_dir', 'mode']) run_dir = os.path.expanduser(FLAGS.run_dir) hparams = model.get_default_hparams() # Command line flags override any of the preceding hyperparameter values. hparams.parse(FLAGS.hparams) run(hparams, run_dir)
def main(unused_argv): output_dir = os.path.expanduser(FLAGS.output_dir) hparams = tf_utils.merge_hparams(constants.DEFAULT_HPARAMS, model.get_default_hparams()) hparams.parse(FLAGS.hparams) # Batch size should always be 1 for inference. hparams.batch_size = 1 tf.logging.info(hparams) tf.gfile.MakeDirs(output_dir) summary_writer = tf.summary.FileWriter(logdir=output_dir) with tf.Session(): run_config = '\n\n'.join([ 'model_dir: ' + FLAGS.model_dir, 'checkpoint_path: ' + str(FLAGS.checkpoint_path), 'examples_path: ' + FLAGS.examples_path, str(hparams), ]) run_config_summary = tf.summary.text('run_config', tf.constant(run_config, name='run_config'), collections=[]) summary_writer.add_summary(run_config_summary.eval()) if FLAGS.eval_loop: assert not FLAGS.checkpoint_path checkpoint_path = None while True: checkpoint_path = tf.contrib.training.wait_for_new_checkpoint( FLAGS.model_dir, last_checkpoint=checkpoint_path) model_inference(model_dir=FLAGS.model_dir, checkpoint_path=checkpoint_path, hparams=hparams, examples_path=FLAGS.examples_path, output_dir=output_dir, summary_writer=summary_writer, master=FLAGS.master, write_summary_every_step=False) else: model_inference(model_dir=FLAGS.model_dir, checkpoint_path=FLAGS.checkpoint_path, hparams=hparams, examples_path=FLAGS.examples_path, output_dir=output_dir, summary_writer=summary_writer, master=FLAGS.master)
def main(unused_argv): tf.logging.set_verbosity(FLAGS.log) tf.app.flags.mark_flags_as_required(['examples_path']) run_dir = os.path.expanduser(FLAGS.run_dir) hparams = tf_utils.merge_hparams(constants.DEFAULT_HPARAMS, model.get_default_hparams()) # Command line flags override any of the preceding hyperparameter values. hparams.parse(FLAGS.hparams) run(hparams, run_dir)
def main(unused_argv): tf.logging.set_verbosity(FLAGS.log) tf.app.flags.mark_flags_as_required(['examples_path']) run_dir = os.path.expanduser(FLAGS.run_dir) hparams = tf_utils.merge_hparams(constants.DEFAULT_HPARAMS, model.get_default_hparams()) # Command line flags override any of the preceding hyperparameter values. hparams.parse(FLAGS.hparams) run(hparams, run_dir)
def main(argv): tf.logging.set_verbosity(FLAGS.log) hparams = tf_utils.merge_hparams(constants.DEFAULT_HPARAMS, model.get_default_hparams()) hparams.parse(FLAGS.hparams) for filename in argv[1:]: tf.logging.info('Generating spectrogram for %s...', filename) spec = create_spec(filename, hparams) spec_filename = filename + '.json' with tf.gfile.Open(spec_filename, 'w') as f: f.write(json.dumps(spec.tolist())) tf.logging.info('Wrote spectrogram json to %s.', spec_filename)
def main(argv): tf.logging.set_verbosity(FLAGS.log) hparams = tf_utils.merge_hparams( constants.DEFAULT_HPARAMS, model.get_default_hparams()) hparams.parse(FLAGS.hparams) for filename in argv[1:]: tf.logging.info('Generating spectrogram for %s...', filename) spec = create_spec(filename, hparams) spec_filename = filename + '.json' with tf.gfile.Open(spec_filename, 'w') as f: f.write(json.dumps(spec.tolist())) tf.logging.info('Wrote spectrogram json to %s.', spec_filename)
def main(unused_argv): tf.logging.set_verbosity(FLAGS.log) if FLAGS.acoustic_checkpoint_filename: acoustic_checkpoint = os.path.join( os.path.expanduser(FLAGS.acoustic_run_dir), 'train', FLAGS.acoustic_checkpoint_filename) else: acoustic_checkpoint = tf.train.latest_checkpoint( os.path.join(os.path.expanduser(FLAGS.acoustic_run_dir), 'train')) run_dir = os.path.expanduser(FLAGS.run_dir) hparams = tf_utils.merge_hparams(constants.DEFAULT_HPARAMS, model.get_default_hparams()) hparams.parse(FLAGS.hparams) tf.gfile.MakeDirs(run_dir) model_inference(acoustic_checkpoint=acoustic_checkpoint, hparams=hparams, examples_path=FLAGS.examples_path, run_dir=run_dir)
def main(unused_argv): tf.logging.set_verbosity(FLAGS.log) if FLAGS.acoustic_checkpoint_filename: acoustic_checkpoint = os.path.join( os.path.expanduser(FLAGS.acoustic_run_dir), 'train', FLAGS.acoustic_checkpoint_filename) else: acoustic_checkpoint = tf.train.latest_checkpoint( os.path.join(os.path.expanduser(FLAGS.acoustic_run_dir), 'train')) run_dir = os.path.expanduser(FLAGS.run_dir) hparams = tf_utils.merge_hparams( constants.DEFAULT_HPARAMS, model.get_default_hparams()) hparams.parse(FLAGS.hparams) tf.gfile.MakeDirs(run_dir) model_inference( acoustic_checkpoint=acoustic_checkpoint, hparams=hparams, examples_path=FLAGS.examples_path, run_dir=run_dir)
def main(argv): tf.logging.set_verbosity(FLAGS.log) hparams = tf_utils.merge_hparams(constants.DEFAULT_HPARAMS, model.get_default_hparams()) # For this script, default to not using cudnn. hparams.use_cudnn = False hparams.parse(FLAGS.hparams) hparams.batch_size = 1 with tf.Graph().as_default(): examples = tf.placeholder(tf.string, [None]) dataset = data.provide_batch(batch_size=1, examples=examples, hparams=hparams, is_training=False, truncated_length=0) estimator = train_util.create_estimator( os.path.expanduser(FLAGS.model_dir), hparams) iterator = dataset.make_initializable_iterator() next_record = iterator.get_next() with tf.Session() as sess: sess.run([ tf.initializers.global_variables(), tf.initializers.local_variables() ]) for filename in argv[1:]: tf.logging.info('Starting transcription for %s...', filename) # The reason we bounce between two Dataset objects is so we can use # the data processing functionality in data.py without having to # construct all the Example protos in memory ahead of time or create # a temporary tfrecord file. tf.logging.info('Processing file...') sess.run(iterator.initializer, {examples: [create_example(filename)]}) def input_fn(): return tf.data.Dataset.from_tensors(sess.run(next_record)) tf.logging.info('Running inference...') checkpoint_path = None if FLAGS.checkpoint_path: checkpoint_path = os.path.expanduser(FLAGS.checkpoint_path) prediction_list = list( estimator.predict(input_fn, checkpoint_path=checkpoint_path, yield_single_examples=False)) assert len(prediction_list) == 1 sequence_prediction = transcribe_audio(prediction_list[0], hparams, FLAGS.frame_threshold, FLAGS.onset_threshold) midi_filename = filename + '.midi' midi_io.sequence_proto_to_midi_file(sequence_prediction, midi_filename) tf.logging.info('Transcription written to %s.', midi_filename)
max_expected_train_example_len=0, onset_length=32, offset_length=32, onset_mode='length_ms', onset_delay=0, min_frame_occupancy_for_label=0.0, jitter_amount_ms=0, min_duration_ms=0, backward_shift_amount_ms=0)) CONFIG_MAP = {} CONFIG_MAP['onsets_frames'] = Config( model_fn=model.model_fn, hparams=tf_utils.merge_hparams(DEFAULT_HPARAMS, model.get_default_hparams()), ) DatasetConfig = collections.namedtuple( 'DatasetConfig', ('name', 'path', 'num_mixes', 'process_for_training')) DATASET_CONFIG_MAP = {} DATASET_CONFIG_MAP['maestro'] = [ DatasetConfig('train', 'gs://magentadata/datasets/maestro/v1.0.0/' 'maestro-v1.0.0_ns_wav_train.tfrecord@10', num_mixes=None, process_for_training=True), DatasetConfig('eval_train', 'gs://magentadata/datasets/maestro/v1.0.0/' 'maestro-v1.0.0_ns_wav_train.tfrecord@10', num_mixes=None,
max_expected_train_example_len=0, onset_length=32, offset_length=32, onset_mode='length_ms', onset_delay=0, min_frame_occupancy_for_label=0.0, jitter_amount_ms=0, min_duration_ms=0, backward_shift_amount_ms=0)) CONFIG_MAP = {} CONFIG_MAP['onsets_frames'] = Config( model_fn=model.model_fn, hparams=tf_utils.merge_hparams(DEFAULT_HPARAMS, model.get_default_hparams()), ) DatasetConfig = collections.namedtuple( 'DatasetConfig', ('name', 'path', 'process_for_training')) DATASET_CONFIG_MAP = {} DATASET_CONFIG_MAP['maestro'] = [ DatasetConfig( 'train', 'gs://magentadata/datasets/maestro/v1.0.0/' 'maestro-v1.0.0_ns_wav_train.tfrecord@10', process_for_training=True), DatasetConfig( 'eval_train',