Skip to content

Commit

Permalink
add feature dictionary conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
keunwoochoi committed Dec 12, 2015
1 parent 74656e0 commit 04948cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions msaf/featextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ def save_features(out_file, features):
Dictionary containing the features.
"""
logging.info("Saving the JSON file in %s" % out_file)
out_json = convert_features(features)
# Actual save
with open(out_file, "w") as f:
json.dump(out_json, f, indent=2)


def convert_features(features):
"""created to enable a not-saving-json case"""
out_json = {"metadata": {"version": {"librosa": librosa.__version__}}}
out_json["analysis"] = {
"dur": features["anal"]["dur"],
Expand Down Expand Up @@ -154,9 +162,7 @@ def save_features(out_file, features):
except:
logging.warning("No annotated beats")

# Actual save
with open(out_file, "w") as f:
json.dump(out_json, f, indent=2)
return out_json


def compute_beat_sync_features(features, beats_idx):
Expand Down
1 change: 1 addition & 0 deletions msaf/input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def get_features(audio_path, annot_beats=False, framesync=False):

return get_features_from_memory(feat, annot_beats, framesync)


def get_features_from_memory(feats, annot_beats=False, framesync=False):

# Beat Synchronous Feats
Expand Down
6 changes: 4 additions & 2 deletions msaf/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,10 @@ def process(in_path, annot_beats=False, feature="hpcp", ds_name="*",
# msaf.utils.ensure_dir(os.path.dirname(file_struct.features_file)) # both lines move to..
# msaf.featextract.save_features(file_struct.features_file, all_features) # ..the end of this function.
# Get correct features
config["features"] = all_features

feats_converted = featextract.convert_features(all_features)
config["features"] = msaf.io.get_features_from_memory(all_features,
annot_beats=annot_beats,
framesync=framesync)
# And run the algorithms
est_times, est_labels = run_algorithms_from_memory(all_features, in_path,
boundaries_id,
Expand Down

0 comments on commit 04948cc

Please sign in to comment.