當前位置: 首頁>>代碼示例>>Python>>正文


Python musdb.DB屬性代碼示例

本文整理匯總了Python中musdb.DB屬性的典型用法代碼示例。如果您正苦於以下問題:Python musdb.DB屬性的具體用法?Python musdb.DB怎麽用?Python musdb.DB使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在musdb的用法示例。


在下文中一共展示了musdb.DB屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _compute_musdb_metrics

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def _compute_musdb_metrics(
        arguments,
        musdb_root_directory,
        audio_output_directory):
    """ Generates musdb metrics fro previsouly computed audio estimation.

    :param arguments: Entrypoint arguments.
    :param audio_output_directory: Directory to get audio estimation from.
    :returns: Path of generated metrics directory.
    """
    metrics_output_directory = join(
        arguments.output_path,
        _METRICS_DIRECTORY)
    get_logger().info('Starting musdb evaluation (this could be long) ...')
    dataset = musdb.DB(
        root=musdb_root_directory,
        is_wav=True,
        subsets=[_SPLIT])
    museval.eval_mus_dir(
        dataset=dataset,
        estimates_dir=audio_output_directory,
        output_dir=metrics_output_directory)
    get_logger().info('musdb evaluation done')
    return metrics_output_directory 
開發者ID:deezer,項目名稱:spleeter,代碼行數:26,代碼來源:evaluate.py

示例2: load_dataset

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def load_dataset(self):

        print('Loading MUSDB18 dataset for singing voice separation...')

        mus = musdb.DB(root_dir=self.path, is_wav=True)
        tracks = mus.load_mus_tracks(subsets='train')
        np.random.seed(seed=1337)
        val_idx = np.random.choice(len(tracks), size=25, replace=False)
        train_idx = [i for i in range(len(tracks)) if i not in val_idx]
        val_tracks = [tracks[i] for i in val_idx]
        train_tracks = [tracks[i] for i in train_idx]
        for condition in ['mixture', 'vocals']:
            self.file_paths['val'][condition] = [track.path[:-11] + condition + '.wav' for track in val_tracks]
        for condition in ['mixture', 'vocals']:
            self.file_paths['train'][condition] = [track.path[:-11] + condition + '.wav' for track in train_tracks]
        self.load_songs()
        return self 
開發者ID:francesclluis,項目名稱:source-separation-wavenet,代碼行數:19,代碼來源:datasets.py

示例3: test_download_and_validation

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def test_download_and_validation():
    mus_all = musdb.DB(download=True)

    assert len(mus_all) == 144

    for track in mus_all:
        assert track.audio.shape[1] > 0
        assert track.audio.shape[-1] == 2
        assert track.stems.shape[0] == 5

    mus_test = musdb.DB(download=True, subsets='test', split=None)
    assert len(mus_test) == 50

    mus_train = musdb.DB(download=True, subsets='train', split='train')
    assert len(mus_train) == 80
    # test validation set
    mus_valid = musdb.DB(download=True, subsets='train', split='valid')
    assert len(mus_valid) == 14

    assert len(mus_train) == len(mus_all) - len(mus_test) - len(mus_valid) 
開發者ID:sigsep,項目名稱:sigsep-mus-db,代碼行數:22,代碼來源:test_parser.py

示例4: main

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def main():
    parser = argparse.ArgumentParser('rawset')
    parser.add_argument('--workers', type=int, default=10)
    parser.add_argument('--samplerate', type=int, default=44100)
    parser.add_argument('--channels', type=int, default=2)
    parser.add_argument('musdb', type=Path)
    parser.add_argument('destination', type=Path)

    args = parser.parse_args()

    build_raw(musdb.DB(root=args.musdb, subsets=["train"], split="train"),
              args.destination / "train",
              normalize=True,
              channels=args.channels,
              samplerate=args.samplerate,
              workers=args.workers)
    build_raw(musdb.DB(root=args.musdb, subsets=["train"], split="valid"),
              args.destination / "valid",
              normalize=True,
              samplerate=args.samplerate,
              channels=args.channels,
              workers=args.workers) 
開發者ID:facebookresearch,項目名稱:demucs,代碼行數:24,代碼來源:raw.py

示例5: musdb_tracks

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def musdb_tracks():
    with tempfile.TemporaryDirectory() as tmp_dir:
        _dir = tmp_dir if fix_dir is None else fix_dir
        db = musdb.DB(root=_dir, download=True)
        yield db 
開發者ID:nussl,項目名稱:nussl,代碼行數:7,代碼來源:conftest.py

示例6: eval_mus_dir

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def eval_mus_dir(
    dataset,
    estimates_dir,
    output_dir=None,
    ext='wav'
):
    """Run evaluation of musdb estimate dir

    Parameters
    ----------
    dataset : DB(object)
        MUSDB18 Database object.
    estimates_dir : str
        Path to estimates folder.
    output_dir : str
        Output folder where evaluation json files are stored.
    ext : str
        estimate file extension, defaults to `wav`
    """
    # create a new musdb instance for estimates with the same file structure
    est = musdb.DB(root=estimates_dir, is_wav=True)
    # get a list of track names
    tracks_to_be_estimated = [t.name for t in est.tracks]

    for track in dataset:
        if track.name not in tracks_to_be_estimated:
            continue
        _load_track_estimates(
            track=track,
            estimates_dir=estimates_dir,
            output_dir=output_dir
        ) 
開發者ID:sigsep,項目名稱:sigsep-mus-eval,代碼行數:34,代碼來源:__init__.py

示例7: museval

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def museval(inargs=None):
    """
    Commandline interface for museval evaluation tools
    """
    parser = argparse.ArgumentParser()

    parser.add_argument(
        'estimates_dir',
        type=str
    )

    parser.add_argument('-o', help='output_dir')

    parser.add_argument(
        '--musdb',
        help='path to musdb',
        type=str
    )

    parser.add_argument(
        '--is-wav', help='Read musdb wav instead of stems',
        action='store_true',
    )

    args = parser.parse_args(inargs)
    mus = musdb.DB(root=args.musdb, is_wav=args.is_wav)

    if not args.o:
        output_dir = args.estimates_dir
    else:
        output_dir = args.o

    # evaluate an existing estimate folder with wav files
    eval_mus_dir(
        dataset=mus,  # instance of musdb
        estimates_dir=args.estimates_dir,  # path to estiamte folder
        output_dir=output_dir,  # set a folder to write eval json files
    ) 
開發者ID:sigsep,項目名稱:sigsep-mus-eval,代碼行數:40,代碼來源:cli.py

示例8: mus

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def mus():
    return musdb.DB(download=True) 
開發者ID:sigsep,項目名稱:sigsep-mus-eval,代碼行數:4,代碼來源:test_regression.py

示例9: produce_musdb_source_estimates

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def produce_musdb_source_estimates(model_config, load_model, musdb_path, output_path, subsets=None):
    '''
    Predicts source estimates for MUSDB for a given model checkpoint and configuration, and evaluate them.
    :param model_config: Model configuration of the model to be evaluated
    :param load_model: Model checkpoint path
    :return: 
    '''
    print("Evaluating trained model saved at " + str(load_model)+ " on MUSDB and saving source estimate audio to " + str(output_path))

    mus = musdb.DB(root_dir=musdb_path)
    predict_fun = lambda track : predict(track, model_config, load_model, output_path)
    assert(mus.test(predict_fun))
    mus.run(predict_fun, estimates_dir=output_path, subsets=subsets) 
開發者ID:f90,項目名稱:Wave-U-Net,代碼行數:15,代碼來源:Evaluate.py

示例10: mus

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def mus(request, subset):
    return musdb.DB(
        root='data/MUS-STEMS-SAMPLE', is_wav=request.param, subsets=subset
    ) 
開發者ID:sigsep,項目名稱:sigsep-mus-db,代碼行數:6,代碼來源:test_parser.py

示例11: mus

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def mus(request):
    return musdb.DB(root='data/MUS-STEMS-SAMPLE', is_wav=request.param) 
開發者ID:sigsep,項目名稱:sigsep-mus-db,代碼行數:4,代碼來源:test_audio_classes.py

示例12: get_musdb_tracks

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def get_musdb_tracks(root, *args, **kwargs):
    mus = musdb.DB(root, *args, **kwargs)
    return {track.name: track.path for track in mus} 
開發者ID:facebookresearch,項目名稱:demucs,代碼行數:5,代碼來源:compressed.py

示例13: getMUSDB

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def getMUSDB(database_path):
    mus = musdb.DB(root_dir=database_path, is_wav=False)

    subsets = list()

    for subset in ["train", "test"]:
        tracks = mus.load_mus_tracks(subset)
        samples = list()

        # Go through tracks
        for track in tracks:
            # Skip track if mixture is already written, assuming this track is done already
            track_path = track.path[:-4]
            mix_path = track_path + "_mix.wav"
            acc_path = track_path + "_accompaniment.wav"
            if os.path.exists(mix_path):
                print("WARNING: Skipping track " + mix_path + " since it exists already")

                # Add paths and then skip
                paths = {"mix" : mix_path, "accompaniment" : acc_path}
                paths.update({key : track_path + "_" + key + ".wav" for key in ["bass", "drums", "other", "vocals"]})

                samples.append(paths)

                continue

            rate = track.rate

            # Go through each instrument
            paths = dict()
            stem_audio = dict()
            for stem in ["bass", "drums", "other", "vocals"]:
                path = track_path + "_" + stem + ".wav"
                audio = track.targets[stem].audio
                soundfile.write(path, audio, rate, "PCM_16")
                stem_audio[stem] = audio
                paths[stem] = path

            # Add other instruments to form accompaniment
            acc_audio = np.clip(sum([stem_audio[key] for key in list(stem_audio.keys()) if key != "vocals"]), -1.0, 1.0)
            soundfile.write(acc_path, acc_audio, rate, "PCM_16")
            paths["accompaniment"] = acc_path

            # Create mixture
            mix_audio = track.audio
            soundfile.write(mix_path, mix_audio, rate, "PCM_16")
            paths["mix"] = mix_path

            diff_signal = np.abs(mix_audio - acc_audio - stem_audio["vocals"])
            print("Maximum absolute deviation from source additivity constraint: " + str(np.max(diff_signal)))# Check if acc+vocals=mix
            print("Mean absolute deviation from source additivity constraint:    " + str(np.mean(diff_signal)))

            samples.append(paths)

        subsets.append(samples)

    return subsets 
開發者ID:f90,項目名稱:Wave-U-Net,代碼行數:59,代碼來源:Datasets.py

示例14: getMUSDB

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def getMUSDB(database_path):
    mus = musdb.DB(root=database_path, is_wav=False)

    subsets = list()

    for subset in ["train", "test"]:
        tracks = mus.load_mus_tracks(subset)
        samples = list()

        # Go through tracks
        for track in sorted(tracks):
            # Skip track if mixture is already written, assuming this track is done already
            track_path = track.path[:-4]
            mix_path = track_path + "_mix.wav"
            acc_path = track_path + "_accompaniment.wav"
            if os.path.exists(mix_path):
                print("WARNING: Skipping track " + mix_path + " since it exists already")

                # Add paths and then skip
                paths = {"mix" : mix_path, "accompaniment" : acc_path}
                paths.update({key : track_path + "_" + key + ".wav" for key in ["bass", "drums", "other", "vocals"]})

                samples.append(paths)

                continue

            rate = track.rate

            # Go through each instrument
            paths = dict()
            stem_audio = dict()
            for stem in ["bass", "drums", "other", "vocals"]:
                path = track_path + "_" + stem + ".wav"
                audio = track.targets[stem].audio
                write_wav(path, audio, rate)
                stem_audio[stem] = audio
                paths[stem] = path

            # Add other instruments to form accompaniment
            acc_audio = np.clip(sum([stem_audio[key] for key in list(stem_audio.keys()) if key != "vocals"]), -1.0, 1.0)
            write_wav(acc_path, acc_audio, rate)
            paths["accompaniment"] = acc_path

            # Create mixture
            mix_audio = track.audio
            write_wav(mix_path, mix_audio, rate)
            paths["mix"] = mix_path

            diff_signal = np.abs(mix_audio - acc_audio - stem_audio["vocals"])
            print("Maximum absolute deviation from source additivity constraint: " + str(np.max(diff_signal)))# Check if acc+vocals=mix
            print("Mean absolute deviation from source additivity constraint:    " + str(np.mean(diff_signal)))

            samples.append(paths)

        subsets.append(samples)

    print("DONE preparing dataset!")
    return subsets 
開發者ID:f90,項目名稱:Wave-U-Net-Pytorch,代碼行數:60,代碼來源:data.py

示例15: musdb_convert

# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def musdb_convert(inargs=None):
    """
    cli application to conver audio files to spectrogram images
    """
    parser = argparse.ArgumentParser()

    parser.add_argument(
        'musdb_root',
        type=str,
    )

    parser.add_argument(
        'output_root',
        type=str
    )

    parser.add_argument(
        '--download', action='store_true', default=False,
        help='use the downloaded 7s musdb stems',
    )

    parser.add_argument(
        '--extension', type=str, default='.wav', 
    )

    parser.add_argument(
        '--hop',
        type=int, default=1024,
        help='hop size in samples, defaults to `1024`'
    )

    args = parser.parse_args(inargs)

    mus = DB(root=args.musdb_root, download=args.download)

    for track in tqdm.tqdm(mus):

        track_estimate_dir = Path(
            args.output_root, track.subset, track.name
        )
        track_estimate_dir.mkdir(exist_ok=True, parents=True)
        # write out tracks to disk

        sf.write(
            track_estimate_dir / Path('mixture').with_suffix(args.extension),
            track.audio,
            track.rate
        )
        for name, track in track.targets.items():
            sf.write(
                track_estimate_dir / Path(name).with_suffix(args.extension),
                track.audio,
                track.rate
            ) 
開發者ID:sigsep,項目名稱:sigsep-mus-db,代碼行數:56,代碼來源:tools.py


注:本文中的musdb.DB屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。