def _build_pcollection(self, pipeline, tfrecord_dirs, ids, split):
    'Build PCollection of examples for split.'
    beam = tfds.core.lazy_imports.apache_beam

    def _emit_base_example(ex):
        'Maps an input example to a TFDS example.'
        beam.metrics.Metrics.counter(split, 'base-examples').inc()
        features = ex.features.feature
        return {'id': features['note_str'].bytes_list.value[0], 'audio': np.array(features['audio'].float_list.value, dtype=np.float32), 'pitch': features['pitch'].int64_list.value[0], 'velocity': features['velocity'].int64_list.value[0], 'instrument': {'label': tf.compat.as_text(features['instrument_str'].bytes_list.value[0]), 'family': tf.compat.as_text(features['instrument_family_str'].bytes_list.value[0]), 'source': tf.compat.as_text(features['instrument_source_str'].bytes_list.value[0])}, 'qualities': {q: features['qualities'].int64_list.value[i] for (i, q) in enumerate(_QUALITIES)}}

    def _in_split(ex, split_ids):
        if ((not split_ids) or (tf.compat.as_text(ex['id']) in split_ids)):
            beam.metrics.Metrics.counter(split, 'in-split').inc()
            return True
        return False

    def _estimate_f0(ex):
        'Estimate the fundamental frequency using CREPE and add to example.'
        ex = ex.copy()
        beam.metrics.Metrics.counter(split, 'estimate-f0').inc()
        (_, f0_hz, f0_confidence, _) = tfds.core.lazy_imports.crepe.predict(ex['audio'], sr=_AUDIO_RATE, viterbi=True, step_size=(1000 / _F0_AND_LOUDNESS_RATE), verbose=0)
        f0_midi = tfds.core.lazy_imports.librosa.core.hz_to_midi(f0_hz)
        f0_midi[(f0_midi == (- np.inf))] = 0
        f0_confidence = np.nan_to_num(f0_confidence)
        ex['f0'] = {'hz': f0_hz.astype(np.float32), 'midi': f0_midi.astype(np.float32), 'confidence': f0_confidence.astype(np.float32)}
        return ex

    def _compute_loudness(ex):
        'Compute loudness and add to example.'
        ex = ex.copy()
        beam.metrics.Metrics.counter(split, 'compute-loudness').inc()
        librosa = tfds.core.lazy_imports.librosa
        n_fft = 2048
        amin = 1e-15
        top_db = 200.0
        stft = librosa.stft(ex['audio'], n_fft=n_fft, hop_length=int((_AUDIO_RATE // _F0_AND_LOUDNESS_RATE)))
        loudness_db = librosa.perceptual_weighting((np.abs(stft) ** 2), librosa.fft_frequencies(_AUDIO_RATE, n_fft=n_fft), amin=amin, top_db=top_db)
        mean_loudness_amp = np.mean(librosa.db_to_amplitude(loudness_db), axis=0)
        mean_loudness_db = librosa.amplitude_to_db(mean_loudness_amp, amin=amin, top_db=top_db)
        ex['loudness'] = {'db': mean_loudness_db.astype(np.float32)}
        return ex
    examples = ((((pipeline | beam.Create([os.path.join(dir_, '*') for dir_ in tfrecord_dirs])) | beam.io.tfrecordio.ReadAllFromTFRecord(coder=beam.coders.ProtoCoder(tf.train.Example))) | beam.Map(_emit_base_example)) | beam.Filter(_in_split, split_ids=ids))
    if self.builder_config.estimate_f0_and_loudness:
        examples = (((examples | beam.Reshuffle()) | beam.Map(_estimate_f0)) | beam.Map(_compute_loudness))
        if (split == tfds.Split.TRAIN):
            loudness = (examples | beam.Map((lambda x: np.mean(x['loudness']['db']))))
            loudness_mean = (loudness | ('loudness_mean' >> beam.combiners.Mean.Globally()))
            loudness_variance = ((loudness | beam.Map((lambda ld, ld_mean: ((ld - ld_mean) ** 2)), ld_mean=beam.pvalue.AsSingleton(loudness_mean))) | ('loudness_variance' >> beam.combiners.Mean.Globally()))
            self.info.metadata['loudness_db_mean'] = loudness_mean
            self.info.metadata['loudness_db_variance'] = loudness_variance
    return examples
Build PCollection of examples for split.
def _build_pcollection(self, pipeline, tfrecord_dirs, ids, split):
    
    beam = tfds.core.lazy_imports.apache_beam

    def _emit_base_example(ex):
        'Maps an input example to a TFDS example.'
        beam.metrics.Metrics.counter(split, 'base-examples').inc()
        features = ex.features.feature
        return {'id': features['note_str'].bytes_list.value[0], 'audio': np.array(features['audio'].float_list.value, dtype=np.float32), 'pitch': features['pitch'].int64_list.value[0], 'velocity': features['velocity'].int64_list.value[0], 'instrument': {'label': tf.compat.as_text(features['instrument_str'].bytes_list.value[0]), 'family': tf.compat.as_text(features['instrument_family_str'].bytes_list.value[0]), 'source': tf.compat.as_text(features['instrument_source_str'].bytes_list.value[0])}, 'qualities': {q: features['qualities'].int64_list.value[i] for (i, q) in enumerate(_QUALITIES)}}

    def _in_split(ex, split_ids):
        if ((not split_ids) or (tf.compat.as_text(ex['id']) in split_ids)):
            beam.metrics.Metrics.counter(split, 'in-split').inc()
            return True
        return False

    def _estimate_f0(ex):
        'Estimate the fundamental frequency using CREPE and add to example.'
        ex = ex.copy()
        beam.metrics.Metrics.counter(split, 'estimate-f0').inc()
        (_, f0_hz, f0_confidence, _) = tfds.core.lazy_imports.crepe.predict(ex['audio'], sr=_AUDIO_RATE, viterbi=True, step_size=(1000 / _F0_AND_LOUDNESS_RATE), verbose=0)
        f0_midi = tfds.core.lazy_imports.librosa.core.hz_to_midi(f0_hz)
        f0_midi[(f0_midi == (- np.inf))] = 0
        f0_confidence = np.nan_to_num(f0_confidence)
        ex['f0'] = {'hz': f0_hz.astype(np.float32), 'midi': f0_midi.astype(np.float32), 'confidence': f0_confidence.astype(np.float32)}
        return ex

    def _compute_loudness(ex):
        'Compute loudness and add to example.'
        ex = ex.copy()
        beam.metrics.Metrics.counter(split, 'compute-loudness').inc()
        librosa = tfds.core.lazy_imports.librosa
        n_fft = 2048
        amin = 1e-15
        top_db = 200.0
        stft = librosa.stft(ex['audio'], n_fft=n_fft, hop_length=int((_AUDIO_RATE // _F0_AND_LOUDNESS_RATE)))
        loudness_db = librosa.perceptual_weighting((np.abs(stft) ** 2), librosa.fft_frequencies(_AUDIO_RATE, n_fft=n_fft), amin=amin, top_db=top_db)
        mean_loudness_amp = np.mean(librosa.db_to_amplitude(loudness_db), axis=0)
        mean_loudness_db = librosa.amplitude_to_db(mean_loudness_amp, amin=amin, top_db=top_db)
        ex['loudness'] = {'db': mean_loudness_db.astype(np.float32)}
        return ex
    examples = ((((pipeline | beam.Create([os.path.join(dir_, '*') for dir_ in tfrecord_dirs])) | beam.io.tfrecordio.ReadAllFromTFRecord(coder=beam.coders.ProtoCoder(tf.train.Example))) | beam.Map(_emit_base_example)) | beam.Filter(_in_split, split_ids=ids))
    if self.builder_config.estimate_f0_and_loudness:
        examples = (((examples | beam.Reshuffle()) | beam.Map(_estimate_f0)) | beam.Map(_compute_loudness))
        if (split == tfds.Split.TRAIN):
            loudness = (examples | beam.Map((lambda x: np.mean(x['loudness']['db']))))
            loudness_mean = (loudness | ('loudness_mean' >> beam.combiners.Mean.Globally()))
            loudness_variance = ((loudness | beam.Map((lambda ld, ld_mean: ((ld - ld_mean) ** 2)), ld_mean=beam.pvalue.AsSingleton(loudness_mean))) | ('loudness_variance' >> beam.combiners.Mean.Globally()))
            self.info.metadata['loudness_db_mean'] = loudness_mean
            self.info.metadata['loudness_db_variance'] = loudness_variance
    return examples