本文整理匯總了Python中jams.load方法的典型用法代碼示例。如果您正苦於以下問題:Python jams.load方法的具體用法?Python jams.load怎麽用?Python jams.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jams
的用法示例。
在下文中一共展示了jams.load方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_info_from_item
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def _get_info_from_item(self, item):
path_to_item = os.path.join(self.folder, item)
item_base_name = os.path.splitext(item)[0]
jam = jams.load(path_to_item)
ann = jam.annotations.search(namespace='scaper')[0]
mix_path = ann.sandbox.scaper['soundscape_audio_path']
source_paths = ann.sandbox.scaper['isolated_events_audio_path']
mix_path = os.path.join(
self.folder, item_base_name + mix_path.split(item_base_name)[-1])
for i, source_path in enumerate(source_paths):
source_paths[i] = os.path.join(
self.folder, item_base_name + source_path.split(item_base_name)[-1])
return jam, ann, mix_path, source_paths
示例2: test_jams_add
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def test_jams_add(tag_data):
fn = 'tests/fixtures/valid.jams'
# The original jam
jam_orig = jams.load(fn)
jam = jams.load(fn)
# Make a new jam with the same metadata and different data
jam2 = jams.load(fn)
ann = jams.Annotation('tag_open', data=tag_data)
jam2.annotations = jams.AnnotationArray(annotations=[ann])
# Add the two
jam.add(jam2)
assert len(jam.annotations) == 3
assert jam.annotations[:-1] == jam_orig.annotations
assert jam.annotations[-1] == jam2.annotations[0]
示例3: test_jams_add_conflict
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def test_jams_add_conflict(on_conflict):
fn = 'tests/fixtures/valid.jams'
# The original jam
jam = jams.load(fn)
jam_orig = jams.load(fn)
# The copy
jam2 = jams.load(fn)
jam2.file_metadata = jams.FileMetadata()
jam.add(jam2, on_conflict=on_conflict)
if on_conflict == 'overwrite':
assert jam.file_metadata == jam2.file_metadata
elif on_conflict == 'ignore':
assert jam.file_metadata == jam_orig.file_metadata
示例4: test_load_invalid
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def test_load_invalid():
def __test_warn(filename, valid, strict):
clean_warning_registry()
with warnings.catch_warnings(record=True) as out:
jams.load(filename, validate=valid, strict=strict)
assert len(out) > 0
assert out[0].category is UserWarning
assert 'failed validating' in str(out[0].message).lower()
# 5. test bad jams file with strict validation
# 6. test bad jams file without strict validation
fn = 'tests/fixtures/invalid.jams'
# Test once with no validation
jams.load(fn, validate=False, strict=False)
# With validation, failure can either be a warning or an exception
with pytest.raises(jams.SchemaError):
jams.load(fn, validate=True, strict=True)
__test_warn(fn, True, False)
示例5: load
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def load(data_home=None):
"""Load GuitarSet
Args:
data_home (str): Local path where GuitarSet is stored.
If `None`, looks for the data in the default directory, `~/mir_datasets`
Returns:
(dict): {`track_id`: track data}
"""
if data_home is None:
data_home = utils.get_default_dataset_path(DATASET_DIR)
guitarset_data = {}
for key in DATA.index.keys():
guitarset_data[key] = Track(key, data_home=data_home)
return guitarset_data
示例6: load_pitch_contour
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def load_pitch_contour(jams_path, string_num):
"""
Args:
jams_path (str): Path of the jams annotation file
string_num (int), in range(6): Which string to load.
0 is the Low E string, 5 is the high e string.
"""
if not os.path.exists(jams_path):
raise IOError("jams_path {} does not exist".format(jams_path))
jam = jams.load(jams_path)
anno_arr = jam.search(namespace='pitch_contour')
anno = anno_arr.search(data_source=str(string_num))[0]
times, values = anno.to_event_values()
frequencies = [v['frequency'] for v in values]
return utils.F0Data(times, frequencies, np.ones_like(times))
示例7: get_duration
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def get_duration(features_file):
"""Reads the duration of a given features file.
Parameters
----------
features_file: str
Path to the JSON file containing the features.
Returns
-------
dur: float
Duration of the analyzed file.
"""
with open(features_file) as f:
feats = json.load(f)
return float(feats["globals"]["dur"])
示例8: test_read_hier_references
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def test_read_hier_references():
one_jams = os.path.join("..", "datasets", "Sargon", "references",
"01-Sargon-Mindless.jams")
three_jams = os.path.join("..", "datasets", "SALAMI", "references",
"SALAMI_200.jams")
audio, fs = librosa.load(audio_file, sr=sr)
y_harmonic, y_percussive = librosa.effects.hpss(audio)
# One level file
hier_bounds, hier_labels, hier_levels = \
msaf.io.read_hier_references(one_jams)
assert len(hier_bounds) == len(hier_labels) and \
len(hier_labels) == len(hier_levels)
assert len(hier_levels) == 1
# Three level file
hier_bounds, hier_labels, hier_levels = \
msaf.io.read_hier_references(three_jams)
assert len(hier_bounds) == len(hier_labels) and \
len(hier_labels) == len(hier_levels)
assert len(hier_levels) == 3
示例9: track_eval
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def track_eval(ann, aud):
model = crema.models.chord.ChordModel()
# Load the audio and make a prediction
track = crema.utils.base(ann)
jam_ref = jams.load(ann, validate=False)
est = model.predict(filename=aud)
try:
scores = jams.eval.chord(jam_ref.annotations['chord', 0],
est)
except ValueError as exc:
print(ann)
print(est.to_dataframe())
print(jam_ref.annotations['chord', 0].to_dataframe())
raise exc
return (track, dict(scores))
示例10: test_save
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def test_save(jam_in, audio_file, strict, fmt):
jam = muda.load_jam_audio(jam_in, audio_file)
_, jamfile = tempfile.mkstemp(suffix='.jams')
_, audfile = tempfile.mkstemp(suffix='.wav')
muda.save(audfile, jamfile, jam, strict=strict, fmt=fmt)
jam2 = muda.load_jam_audio(jamfile, audfile, fmt=fmt)
jam2_raw = jams.load(jamfile, fmt=fmt)
os.unlink(audfile)
os.unlink(jamfile)
assert hasattr(jam2.sandbox, 'muda')
assert '_audio' in jam2.sandbox.muda
assert '_audio' not in jam2_raw.sandbox.muda
duration = librosa.get_duration(**jam2.sandbox.muda['_audio'])
assert jam2.file_metadata.duration == duration
示例11: compare_beats
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def compare_beats(f_ref, f_est):
# f_ref contains the reference annotations
j_ref = jams.load(f_ref)
# f_est contains the estimated annotations
j_est = jams.load(f_est)
# Get the first reference beats
beat_ref = j_ref.search(namespace='beat')[0]
beat_est = j_est.search(namespace='beat')[0]
# Get the scores
return jams.eval.beat(beat_ref, beat_est)
示例12: input_jam
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def input_jam():
return jams.load('tests/fixtures/valid.jams')
示例13: test_jams_save
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def test_jams_save(input_jam, output_path):
input_jam.save(output_path)
reload_jam = jams.load(output_path)
assert input_jam == reload_jam
示例14: test_jams_validate_good
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def test_jams_validate_good():
fn = 'tests/fixtures/valid.jams'
j1 = jams.load(fn, validate=False)
j1.validate()
j1.file_metadata.validate()
示例15: jam_validate
# 需要導入模塊: import jams [as 別名]
# 或者: from jams import load [as 別名]
def jam_validate():
j1 = jams.load('tests/fixtures/invalid.jams', validate=False)
return j1