(exclude_ids)
Generate the train TFRecord.
Generate the train TFRecord.
Generate the train TFRecord .
def generate_train_set(exclude_ids):
  """Generate the train TFRecord."""
  train_file_pairs = []
  for directory in train_dirs:
    path = os.path.join(FLAGS.input_dir, directory)
    path = os.path.join(path, '*.wav')
    wav_files = glob.glob(path)
    # find matching mid files
    for wav_file in wav_files:
      base_name_root, _ = os.path.splitext(wav_file)
      mid_file = base_name_root + '.mid'
      if filename_to_id(wav_file) not in exclude_ids:
        train_file_pairs.append((wav_file, mid_file))

  train_output_name = os.path.join(FLAGS.output_dir,
                                   'maps_config2_train.tfrecord')

  with tf.python_io.TFRecordWriter(train_output_name) as writer:
    for idx, pair in enumerate(train_file_pairs):
      print('{} of {}: {}'.format(idx, len(train_file_pairs), pair[0]))
      # load the wav data
      wav_data = tf.gfile.Open(pair[0], 'rb').read()
      # load the midi data and convert to a notesequence
      ns = midi_io.midi_file_to_note_sequence(pair[1])
      for example in audio_label_data_utils.process_record(
          wav_data, ns, pair[0], FLAGS.min_length, FLAGS.max_length,
          FLAGS.sample_rate):
        writer.write(example.SerializeToString())
def generate_train_set ( exclude_ids ) : train_file_pairs = [ ] for directory in train_dirs : path = os . path . join ( FLAGS . input_dir , directory ) path = os . path . join ( path , '*.wav' ) wav_files = glob . glob ( path ) # find matching mid files for wav_file in wav_files : base_name_root , _ = os . path . splitext ( wav_file ) mid_file = base_name_root + '.mid' if filename_to_id ( wav_file ) not in exclude_ids : train_file_pairs . append ( ( wav_file , mid_file ) ) train_output_name = os . path . join ( FLAGS . output_dir , 'maps_config2_train.tfrecord' ) with tf . python_io . TFRecordWriter ( train_output_name ) as writer : for idx , pair in enumerate ( train_file_pairs ) : print ( '{} of {}: {}' . format ( idx , len ( train_file_pairs ) , pair [ 0 ] ) ) # load the wav data wav_data = tf . gfile . Open ( pair [ 0 ] , 'rb' ) . read ( ) # load the midi data and convert to a notesequence ns = midi_io . midi_file_to_note_sequence ( pair [ 1 ] ) for example in audio_label_data_utils . process_record ( wav_data , ns , pair [ 0 ] , FLAGS . min_length , FLAGS . max_length , FLAGS . sample_rate ) : writer . write ( example . SerializeToString ( ) )