MarkGotham / When-in-Rome

meta-corpus of and code library for the functional harmonic analysis of music
58 stars 12 forks source link

Add automatic analyses by AugmentedNet of entire corpus #47

Closed napulen closed 2 years ago

napulen commented 2 years ago

Running an automatic analysis on any folder with a score.mxl file in it within the Corpus of the repo.

For completeness, the script to run the analyses is

import os
import shutil

from AugmentedNet.inference import batch, predict
from AugmentedNet.utils import tensorflowGPUHack
from tensorflow import keras

if __name__ == "__main__":
    tensorflowGPUHack()
    modelPath = "AugmentedNet.hdf5"
    model = keras.models.load_model(modelPath)
    for root, _, files in sorted(os.walk("../When-in-Rome/Corpus")):
        for f in files:
            if f != "score.mxl":
                continue
            path = os.path.join(root, f)
            pathrntxt = path.replace(".mxl", "_annotated.rntxt")
            annotatedScore = path.replace(".mxl", "_annotated.xml")
            annotationCSV = path.replace(".mxl", "_annotated.csv")
            newrntxt = path.replace("score.mxl", "analysis_automatic.rntxt")
            print(path)
            if os.path.isfile(newrntxt):
                print("Already there, skipping!!!!!!!!!!!!!!!")
                continue
            try:
                predict(model, inputPath=path)
            except:
                pass
            if os.path.isfile(annotatedScore):
                os.remove(annotatedScore)
            if os.path.isfile(annotationCSV):
                os.remove(annotationCSV)
            if os.path.isfile(pathrntxt):
                shutil.move(pathrntxt, newrntxt)
MarkGotham commented 2 years ago

Thanks @napulen ! Great to have this across the whole corpus for many reasons including:

Merging. Still plenty to discuss within those analyses of course. Where do you want reports on issues? Here? On augmented net? Not at all? ;)

napulen commented 2 years ago

How about reports on invalid rntxt syntax and similar bugs can go on AugmentedNet, whereas corrections to analyses can go here

napulen commented 2 years ago

If a particular analysis is suspiciously bad compared to the average, let's treat it as a software bug, because it probably is