Skip to content

Commit

Permalink
Merge pull request #97 from napulen/v180
Browse files Browse the repository at this point in the history
V180
  • Loading branch information
napulen authored Jun 25, 2022
2 parents 9ca4e14 + 08f4a4c commit bf6069b
Show file tree
Hide file tree
Showing 42 changed files with 217,728 additions and 673 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,5 @@ defaults.json

# Ignore memmap files
*.mmap

notebooks/**/*.png
Binary file modified AugmentedNet.hdf5
Binary file not shown.
2 changes: 1 addition & 1 deletion AugmentedNet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import glob

__author__ = "Néstor Nápoles López"
__version__ = "1.7.1"
__version__ = "1.8.0"
modules = glob.glob(join(dirname(__file__), "*.py"))
__all__ = [
basename(f)[:-3]
Expand Down
26 changes: 19 additions & 7 deletions AugmentedNet/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,29 @@ class DefaultArguments(object):
npz = {
"synthetic": False,
"texturizeEachTransposition": False,
"dataAugmentation": True,
"noTransposition": False,
"collections": ["bps"],
"testCollections": ["bps"],
"inputRepresentations": ["Bass19", "Chromagram19"],
"inputRepresentations": [
"Bass19",
"Chromagram19",
"MeasureNoteOnset14",
],
"outputRepresentations": [
"Alto35",
"Bass35",
# "ChordQuality11",
# "ChordRoot35",
"HarmonicRhythm7",
# "Inversion4",
"LocalKey35",
"LocalKey38",
"PitchClassSet121",
# "PrimaryDegree22",
"RomanNumeral31",
# "SecondaryDegree22",
"Soprano35",
"Tenor35",
"TonicizedKey35",
"TonicizedKey38",
],
"sequenceLength": 640,
"scrutinizeData": False,
Expand Down Expand Up @@ -117,9 +121,9 @@ def npz(is_parent_parser=False):
help="Include training files from a specific corpus/collection.",
)
parser.add_argument(
"--dataAugmentation",
"--noTransposition",
action="store_true",
help="Perform data augmentation on the training set.",
help="Disable transposition data augmentation on the training set.",
)
parser.add_argument(
"--inputRepresentations",
Expand Down Expand Up @@ -183,7 +187,15 @@ def train():
parser = ArgumentParser(description=train_description, parents=parents)
parser.add_argument(
"experiment_name",
choices=["testset", "validationset", "prototyping", "debug"],
choices=[
"local",
"computecanada",
"colab",
"ablation",
"validationset",
"testset",
"debug",
],
help="A short name for this experiment.",
)
parser.add_argument(
Expand Down
10 changes: 2 additions & 8 deletions AugmentedNet/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Common hardcoded variables throughout the code."""

from .data import available_collections
from .data import getAnnotationScoreDataset

# Number of decimals to the right of the decimal point
FLOATSCALE = 4
Expand All @@ -11,10 +11,4 @@

DATASETSUMMARYFILE = "dataset_summary.tsv"

ANNOTATIONSCOREDUPLES = {}
DATASPLITS = {"training": [], "validation": [], "test": []}

for module in available_collections.values():
ANNOTATIONSCOREDUPLES.update(module.annotation_score_duples)
for split in DATASPLITS:
DATASPLITS[split].extend(module.splits[split])
ANNOTATIONSCOREDUPLES, DATASPLITS = getAnnotationScoreDataset()
18 changes: 17 additions & 1 deletion AugmentedNet/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@
available_collections = {
"abc": abc_dcml,
"bps": bps,
"haydnop20": haydnsun,
"haydnsun": haydnsun,
"mps": mps,
"tavern": tavern,
"wir": wir,
"wirwtc": wirwtc,
}


def getAnnotationScoreDataset(collections=[]):
"""Return the available (annotation, score) pairs in the dataset."""
allCollections = list(available_collections.keys())
collections = collections or allCollections
duples = {}
splits = {"training": [], "validation": [], "test": []}
for collection in collections:
if collection not in allCollections:
raise KeyError()
module = available_collections[collection]
duples.update(module.annotation_score_duples)
for split in splits:
splits[split].extend(module.splits[split])
return duples, splits
96 changes: 48 additions & 48 deletions AugmentedNet/data/haydnsun.py
Original file line number Diff line number Diff line change
@@ -1,131 +1,131 @@
annotation_score_duples = {
"haydnop20-no1-1": (
"haydnsun-no1-1": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No1/1/analysis.txt",
"rawdata/haydn_op20_harm/op20/1/i/op20n1-01.krn",
),
"haydnop20-no1-2": (
"haydnsun-no1-2": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No1/2/analysis.txt",
"rawdata/haydn_op20_harm/op20/1/ii/op20n1-02.krn",
),
"haydnop20-no1-3": (
"haydnsun-no1-3": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No1/3/analysis.txt",
"rawdata/haydn_op20_harm/op20/1/iii/op20n1-03.krn",
),
"haydnop20-no1-4": (
"haydnsun-no1-4": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No1/4/analysis.txt",
"rawdata/haydn_op20_harm/op20/1/iv/op20n1-04.krn",
),
"haydnop20-no2-1": (
"haydnsun-no2-1": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No2/1/analysis.txt",
"rawdata/haydn_op20_harm/op20/2/i/op20n2-01.krn",
),
"haydnop20-no2-2": (
"haydnsun-no2-2": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No2/2/analysis.txt",
"rawdata/haydn_op20_harm/op20/2/ii/op20n2-02.krn",
),
"haydnop20-no2-3": (
"haydnsun-no2-3": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No2/3/analysis.txt",
"rawdata/haydn_op20_harm/op20/2/iii/op20n2-03.krn",
),
"haydnop20-no2-4": (
"haydnsun-no2-4": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No2/4/analysis.txt",
"rawdata/haydn_op20_harm/op20/2/iv/op20n2-04.krn",
),
"haydnop20-no3-1": (
"haydnsun-no3-1": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No3/1/analysis.txt",
"rawdata/haydn_op20_harm/op20/3/i/op20n3-01.krn",
),
"haydnop20-no3-2": (
"haydnsun-no3-2": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No3/2/analysis.txt",
"rawdata/haydn_op20_harm/op20/3/ii/op20n3-02.krn",
),
"haydnop20-no3-3": (
"haydnsun-no3-3": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No3/3/analysis.txt",
"rawdata/haydn_op20_harm/op20/3/iii/op20n3-03.krn",
),
"haydnop20-no3-4": (
"haydnsun-no3-4": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No3/4/analysis.txt",
"rawdata/haydn_op20_harm/op20/3/iv/op20n3-04.krn",
),
"haydnop20-no4-1": (
"haydnsun-no4-1": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No4/1/analysis.txt",
"rawdata/haydn_op20_harm/op20/4/i/op20n4-01.krn",
),
"haydnop20-no4-2": (
"haydnsun-no4-2": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No4/2/analysis.txt",
"rawdata/haydn_op20_harm/op20/4/ii/op20n4-02.krn",
),
"haydnop20-no4-3": (
"haydnsun-no4-3": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No4/3/analysis.txt",
"rawdata/haydn_op20_harm/op20/4/iii/op20n4-03.krn",
),
"haydnop20-no4-4": (
"haydnsun-no4-4": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No4/4/analysis.txt",
"rawdata/haydn_op20_harm/op20/4/iv/op20n4-04.krn",
),
"haydnop20-no5-1": (
"haydnsun-no5-1": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No5/1/analysis.txt",
"rawdata/haydn_op20_harm/op20/5/i/op20n5-01.krn",
),
"haydnop20-no5-2": (
"haydnsun-no5-2": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No5/2/analysis.txt",
"rawdata/haydn_op20_harm/op20/5/ii/op20n5-02.krn",
),
"haydnop20-no5-3": (
"haydnsun-no5-3": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No5/3/analysis.txt",
"rawdata/haydn_op20_harm/op20/5/iii/op20n5-03.krn",
),
"haydnop20-no5-4": (
"haydnsun-no5-4": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No5/4/analysis.txt",
"rawdata/haydn_op20_harm/op20/5/iv/op20n5-04.krn",
),
"haydnop20-no6-1": (
"haydnsun-no6-1": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No6/1/analysis.txt",
"rawdata/haydn_op20_harm/op20/6/i/op20n6-01.krn",
),
"haydnop20-no6-2": (
"haydnsun-no6-2": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No6/2/analysis.txt",
"rawdata/haydn_op20_harm/op20/6/ii/op20n6-02.krn",
),
"haydnop20-no6-3": (
"haydnsun-no6-3": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No6/3/analysis.txt",
"rawdata/haydn_op20_harm/op20/6/iii/op20n6-03.krn",
),
"haydnop20-no6-4": (
"haydnsun-no6-4": (
"rawdata/When-in-Rome/Corpus/Quartets/Haydn,_Franz_Joseph/Op20_No6/4/analysis.txt",
"rawdata/haydn_op20_harm/op20/6/iv/op20n6-04.krn",
),
}

splits = {
"training": [
"haydnop20-no6-3",
"haydnop20-no1-1",
"haydnop20-no4-1",
"haydnop20-no4-3",
"haydnop20-no1-3",
"haydnop20-no6-2",
"haydnop20-no3-1",
"haydnop20-no5-1",
"haydnop20-no1-4",
"haydnop20-no2-3",
"haydnop20-no5-4",
"haydnop20-no3-2",
"haydnop20-no4-4",
"haydnop20-no2-1",
"haydnop20-no4-2",
"haydnop20-no6-1",
"haydnsun-no6-3",
"haydnsun-no1-1",
"haydnsun-no4-1",
"haydnsun-no4-3",
"haydnsun-no1-3",
"haydnsun-no6-2",
"haydnsun-no3-1",
"haydnsun-no5-1",
"haydnsun-no1-4",
"haydnsun-no2-3",
"haydnsun-no5-4",
"haydnsun-no3-2",
"haydnsun-no4-4",
"haydnsun-no2-1",
"haydnsun-no4-2",
"haydnsun-no6-1",
],
"validation": [
"haydnop20-no1-2",
"haydnop20-no2-4",
"haydnop20-no3-3",
"haydnop20-no5-2",
"haydnsun-no1-2",
"haydnsun-no2-4",
"haydnsun-no3-3",
"haydnsun-no5-2",
],
"test": [
"haydnop20-no2-2",
"haydnop20-no3-4",
"haydnop20-no5-3",
"haydnop20-no6-4",
"haydnsun-no2-2",
"haydnsun-no3-4",
"haydnsun-no5-3",
"haydnsun-no6-4",
],
}
8 changes: 4 additions & 4 deletions AugmentedNet/dataset_npz_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def correctSplit(split, testSetOn):
def generateDataset(
synthetic,
texturizeEachTransposition,
dataAugmentation,
noTransposition,
collections,
testCollections,
inputRepresentations,
Expand Down Expand Up @@ -108,11 +108,11 @@ def generateDataset(
df = joint_parser.from_tsv(tsvlocation)
if scrutinizeData and split == "training":
df = scrutinize(df)
if dataAugmentation and split == "training":
if noTransposition or split != "training":
transpositions = ["P1"]
else:
transpositions = _getTranspositions(df, transpositionKeys)
print("\t", transpositions)
else:
transpositions = ["P1"]
if synthetic:
if not texturizeEachTransposition:
# once per file
Expand Down
4 changes: 2 additions & 2 deletions AugmentedNet/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def predict(model, inputPath):
if not notes:
continue
bass = sorted(notes, key=lambda n: n[1])[0][0]
thiskey = analysis.LocalKey35
tonicizedKey = analysis.TonicizedKey35
thiskey = analysis.LocalKey38
tonicizedKey = analysis.TonicizedKey38
pcset = analysis.PitchClassSet121
rn2, chordLabel = resolveRomanNumeral(
analysis.Bass35,
Expand Down
Loading

0 comments on commit bf6069b

Please sign in to comment.