本文整理匯總了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
示例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
示例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)
示例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)
示例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
示例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
)
示例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
)
示例8: mus
# 需要導入模塊: import musdb [as 別名]
# 或者: from musdb import DB [as 別名]
def mus():
return musdb.DB(download=True)
示例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)
示例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
)
示例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)
示例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}
示例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
示例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
示例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
)