Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
430 commits
Select commit Hold shift + click to select a range
c653f00
git_ignore
jdasam Sep 3, 2018
9a5ec4c
test
jdasam Sep 3, 2018
f50b59b
Merge remote-tracking branch 'origin/rnn_model' into rnn_model
jdasam Sep 3, 2018
bf56bc4
pedal_cut done after the note
jdasam Sep 3, 2018
3d871bf
Merge branch 'rnn_model' of https://github.com/jdasam/musicXML-parser…
TaegyunKwon Sep 4, 2018
92fb70e
Merge remote-tracking branch 'head_origin/master' into rnn_model
TaegyunKwon Sep 4, 2018
371aafc
minor grammer change
TaegyunKwon Sep 4, 2018
bbd3ae1
clean up indentation
TaegyunKwon Sep 4, 2018
4894cec
Merge @jdasm's (#19)
sujinleeme Sep 5, 2018
e325ed7
update init
sujinleeme Sep 5, 2018
74b0d6a
remove test file
sujinleeme Sep 5, 2018
8923643
Merge pull request #20 from mac-marg-pianist/init
TaegyunKwon Sep 5, 2018
6543364
Add Note.mearsure_number attr
TaegyunKwon Sep 6, 2018
19a750f
Merge pull request #21 from TaegyunKwon/master
sujinleeme Sep 6, 2018
bafecfd
cut time to absolute second
jdasam Sep 8, 2018
e6710e3
folder structure changed
jdasam Sep 8, 2018
22c916a
merged
jdasam Oct 11, 2018
6f0667b
cleaned
jdasam Oct 11, 2018
a4e8c43
Revert "cleaned"
jdasam Oct 11, 2018
4f38234
Revert "Revert "cleaned""
jdasam Oct 11, 2018
1909760
input dir fixed
jdasam Oct 11, 2018
0db68bd
fix error when direction has no staff
jdasam Oct 26, 2018
2217537
deal repeat
jdasam Nov 24, 2018
479bbb8
read several-lines words
jdasam Nov 24, 2018
4699404
read staff only text exists
jdasam Nov 24, 2018
39db721
find first ending stop if it is discontinue
jdasam Nov 27, 2018
6f08473
fix error when the musicXML does not start with tempo direction
jdasam Nov 29, 2018
1a979d0
Merge branch 'rnn_model' of https://github.com/jdasam/musicXML-parser…
jdasam Dec 14, 2018
848c9ba
Merge branch 'rnn_model' of https://github.com/jdasam/musicXML-parser…
jdasam Dec 14, 2018
10b64a1
several updates
jdasam Dec 14, 2018
a9fb3d1
Merge branch 'rnn_model' of https://github.com/jdasam/musicXML-parser…
jdasam Dec 14, 2018
60368db
delete print
jdasam Dec 14, 2018
93e80fa
read beam status
jdasam Dec 17, 2018
22ba2f1
fix time signature when the symbol is 'cut' (2/2)
jdasam Dec 17, 2018
8f3aaa4
feature added
jdasam Dec 19, 2018
d6b7a97
direction words parsing
jdasam Jan 1, 2019
49bdc08
change after grace note
jdasam Jan 7, 2019
ee67b1e
wip pedal fix?
jdasam Jan 11, 2019
c89dae3
typo fixed
jdasam Jan 11, 2019
24359a5
notations.is_arpeggiate error fixed
Mar 5, 2019
d02aced
fix notation fermata, add accidental
Apr 17, 2019
23b8b74
fix some issues
May 4, 2019
e566553
add is_first_grace_note
jdasam May 16, 2019
e6eea4e
Merge pull request #1 from jdasam/rnn_model
jdasam May 16, 2019
d5b2923
add line break
jdasam May 16, 2019
4034691
extract_notes to class method
jdasam May 17, 2019
db27849
add get_direction
jdasam May 21, 2019
f581baa
solve missing first ending
jdasam Jul 3, 2019
4608619
change path to work in submodule
jdasam Aug 4, 2019
038b08f
Update musicxml_parser
jdasam Aug 4, 2019
07c136a
change test code
jdasam Aug 4, 2019
9ad9456
delete beam state error
jdasam Sep 21, 2019
9165d7a
Update xml_to_midi_script.py
jdasam Sep 23, 2019
2a0d5dd
add pedal refresh weight, features to vector
jdasam Sep 26, 2019
93650ac
change articulation loss weight
jdasam Sep 26, 2019
61baed8
summarized codes
jdasam Oct 3, 2019
ebdacf7
fix is_tirll when dealing wavy notation
jdasam Nov 7, 2019
5a247a4
add prokofiev 7 directions
jdasam Nov 8, 2019
3a83515
fix error
jdasam Nov 19, 2019
1b6833d
Update midi_utils
jdasam Nov 19, 2019
bcfd829
Update .gitignore
jdasam Nov 19, 2019
1512a7b
edit read perform pair
jdasam Nov 24, 2019
684ff0f
copy and align for emotion data
jdasam Nov 24, 2019
7d94d9e
Update midi_utils
jdasam Nov 24, 2019
dcabb9b
Add playable_note.py add classify_note.py to replace check_note_statu…
TaegyunKwon Jan 2, 2020
a8aabf7
Modified playable_notes.py add mark_preceded_by_grace_note_to_chord_n…
TaegyunKwon Jan 2, 2020
86c4bca
Modified playable_note.py move related fuctions
TaegyunKwon Jan 2, 2020
184fb7b
move get_notes part to playable_notes
TaegyunKwon Jan 2, 2020
02b1b7c
delete recursive object (state.previous_note)
jdasam Jan 7, 2020
09abb3f
change Cresciuto to global class
jdasam Jan 9, 2020
850287d
refactoring code using class
jdasam Jan 13, 2020
b11d506
add score extractor
jdasam Jan 13, 2020
901387c
first commit
luciaicull Jan 13, 2020
30fd8c7
Modified xml_matching.py change get_note_location to process over who…
TaegyunKwon Jan 13, 2020
2a0b06f
Modified xml_matching.py change get_note_location to process over who…
TaegyunKwon Jan 13, 2020
0e91bd5
copied DataSet class from xml_matching.py
luciaicull Jan 13, 2020
e25a1f0
Merge pull request #3 from luciaicull/refactoring
jdasam Jan 13, 2020
79feff8
delete DataSet class(-> data_class.py)
luciaicull Jan 13, 2020
6f773d4
modified get_note_location delete state
TaegyunKwon Jan 13, 2020
f96a001
add extract_accidental
jdasam Jan 13, 2020
bd40a21
Modify xml_matching.ScoreExtractor change extraction unit. note->piece
TaegyunKwon Jan 13, 2020
2704042
remove prints in playable_notes.py
TaegyunKwon Jan 13, 2020
a75acdd
move get_notes part to get_playable_notes.py
TaegyunKwon Jan 13, 2020
9faa03f
Modify main.get_notes to return rests, as well as notes
TaegyunKwon Jan 13, 2020
2ef39e9
move PieceData from xml_matching.py, removed feature extraction process
luciaicull Jan 13, 2020
3caabca
move binary_index() from binary_index.py
luciaicull Jan 13, 2020
3a7fa03
move binary_index() to utils.py
luciaicull Jan 13, 2020
ed7e623
move methods from xml_matching.py forData classes
luciaicull Jan 13, 2020
107e366
removed codes for DataSet, PieceData, PieceMeta classes
luciaicull Jan 13, 2020
7170dac
removed codes for PerformData class
luciaicull Jan 13, 2020
9aef785
add PerformData class
luciaicull Jan 13, 2020
d637085
add methods from xml_matching.py for feature_extraction.py
luciaicull Jan 13, 2020
0fc79cc
remove codes for feature_extraction.py
luciaicull Jan 13, 2020
9338a29
add initial codes for feature extraction process
luciaicull Jan 13, 2020
35426c4
fix minor errors
luciaicull Jan 13, 2020
d885774
merged
TaegyunKwon Jan 13, 2020
3baa45b
Merge branch 'refactoring' of https://github.com/jdasam/pyScoreParser…
TaegyunKwon Jan 13, 2020
9dba324
move make_index_continous->feature_extraction.py
TaegyunKwon Jan 13, 2020
cbdc5e0
Merge pull request #1 from TaegyunKwon/refactory
luciaicull Jan 13, 2020
8a335c9
Merge https://github.com/luciaicull/pyScoreParser into refactoring_yj
luciaicull Jan 13, 2020
076d958
Merge branch 'refactoring' of https://github.com/luciaicull/pyScorePa…
luciaicull Jan 13, 2020
9080948
relocate functions
jdasam Jan 14, 2020
e0f4a6f
Merge branch 'refactoring' into refactory
jdasam Jan 14, 2020
eeb6788
Merge pull request #2 from TaegyunKwon/refactory
jdasam Jan 14, 2020
940f00e
Merge pull request #4 from luciaicull/refactoring
jdasam Jan 14, 2020
d410a0d
add comments on function
jdasam Jan 14, 2020
f4e142c
delete unused method in ScoreExtractor
luciaicull Jan 14, 2020
d0f33df
move codes to feature_utils.py
luciaicull Jan 14, 2020
dcf489d
move codes about utilities from feature_extraction.py
luciaicull Jan 14, 2020
dda9870
revive feature extraction code in DataSet
jdasam Jan 14, 2020
7c53b95
WIP - PerformExtractor
jdasam Jan 14, 2020
39631e9
relocate old functions
jdasam Jan 14, 2020
98500bc
relocate functions
jdasam Jan 14, 2020
457850f
minor changes
luciaicull Jan 15, 2020
da535e4
merge:
luciaicull Jan 15, 2020
717f930
add _load_composer_name()
luciaicull Jan 15, 2020
dcb3e97
add functions for PerformExtractor
jdasam Jan 15, 2020
58abda3
delete previous codes
jdasam Jan 16, 2020
c518948
change function name
jdasam Jan 16, 2020
d2d7423
change function name
jdasam Jan 16, 2020
467e713
Update musicxml_parser
jdasam Jan 16, 2020
d07d7c9
move functions
jdasam Jan 16, 2020
2e9521d
Fix errors
jdasam Jan 16, 2020
68bfcd5
relocate make_available_xml_midi_positions
jdasam Jan 16, 2020
d49cde9
change PositionPair into dictionary
jdasam Jan 17, 2020
ce71b13
fix PerformExtractor functions
jdasam Jan 17, 2020
d892f86
mark error
jdasam Jan 17, 2020
ab4eb90
Merge branch 'watch_total' into refactoring_yj
luciaicull Jan 20, 2020
74231dd
fix get articulation error
jdasam Jan 23, 2020
2e0a217
delete old functions
jdasam Jan 23, 2020
eae92bd
change feature list axis
jdasam Jan 28, 2020
41c9787
add attack_deviation by hands (staff)
jdasam Jan 28, 2020
72da154
add comments
luciaicull Jan 29, 2020
f24cb48
minor change
luciaicull Jan 29, 2020
70b0f2e
merged
luciaicull Jan 29, 2020
4c6ffd9
minor import change
luciaicull Jan 29, 2020
b338acf
update .gitmodule change default branch refactoring
TaegyunKwon Jan 29, 2020
117d117
add import issues
luciaicull Jan 29, 2020
74deb8c
minor fix pedal_cleaning.py import binary_index
TaegyunKwon Jan 29, 2020
10d3dd7
add composer name parser
TaegyunKwon Jan 29, 2020
53f0726
deal error case when other-dynamics has no content
jdasam Jan 29, 2020
8204b33
prevent error when there is no absolute direction before
jdasam Jan 29, 2020
5d8ca25
Modified featrue_extraction.py modified Score Extractor. add more ext…
TaegyunKwon Jan 29, 2020
b742c9c
remove legacys in ScoreExtractor
TaegyunKwon Jan 29, 2020
4c16c93
move composer_to_vec from xml_matching.py -> feature_extraction.py
TaegyunKwon Jan 29, 2020
198c192
add test code
TaegyunKwon Jan 29, 2020
8fb6c5c
add success message
TaegyunKwon Jan 29, 2020
378f392
change relative import in xml_utils.py
TaegyunKwon Jan 29, 2020
be9122d
Update musicxml_parser
jdasam Jan 29, 2020
b5873e8
add refactoring branch
luciaicull Jan 29, 2020
7e00cdc
minor change
luciaicull Jan 29, 2020
ac07145
move methods to feature_utils.py
luciaicull Jan 29, 2020
276026b
add new methods from feature_extraction.py
luciaicull Jan 29, 2020
e33697d
remove minor comments
luciaicull Jan 29, 2020
d279c81
delete file
luciaicull Jan 29, 2020
67638a8
update watching branch
luciaicull Jan 29, 2020
5067e91
fix error when abs direction is None
jdasam Jan 29, 2020
cce9680
My test code for feature extraction
jdasam Jan 29, 2020
bd6dc7d
WIP, DataSet for EmotionData
jdasam Jan 29, 2020
cc68359
change watching branch
luciaicull Jan 29, 2020
dd51b41
change watching branch
luciaicull Jan 29, 2020
d94aab5
change import path as relative import
TaegyunKwon Jan 30, 2020
7fb54e0
Merge branch 'refactoring' into refactory
TaegyunKwon Jan 30, 2020
297b93c
reflect midi_utils update
TaegyunKwon Jan 30, 2020
29f911e
change midi_utils origin branch master->continuos_pedal
TaegyunKwon Jan 30, 2020
6737dc2
modify import part
luciaicull Jan 30, 2020
8687304
modify import part
luciaicull Jan 30, 2020
904b68a
add comments
luciaicull Jan 30, 2020
568f213
Merge pull request #10 from luciaicull/refactoring_yj
jdasam Jan 30, 2020
d48df78
fix articulation error
jdasam Jan 30, 2020
9e5d96f
handle dataset structured with file name
jdasam Jan 30, 2020
7628973
fix wavy_line error
jdasam Jan 30, 2020
579e6c2
Update musicxml_parser
jdasam Jan 30, 2020
2489502
Update test_code.py
jdasam Jan 30, 2020
2d29087
Merge branch 'refactoring' of https://github.com/jdasam/pyScoreParser…
jdasam Jan 30, 2020
2616098
Merge branch 'refactoring' into refactory
jdasam Jan 30, 2020
82bd8e9
Merge pull request #9 from TaegyunKwon/refactory
jdasam Jan 30, 2020
0a59541
fix function path to feature_utils.py
jdasam Jan 30, 2020
b9b0378
change import, move composer_name_to_vec
jdasam Jan 30, 2020
05a4262
fix composer name for emotionDataset
jdasam Jan 30, 2020
af017a3
minor import modification
luciaicull Jan 30, 2020
8ead0e6
Merge branch 'watch_total' into refactoring_yj
luciaicull Jan 30, 2020
75acf98
musicxml_name fixed, composer name fixed
jdasam Jan 30, 2020
31c73e2
minor test code modification
luciaicull Jan 30, 2020
7ef51c0
Merge branch 'refactoring' of https://github.com/jdasam/pyScoreParser…
luciaicull Jan 30, 2020
9a0ccfc
update tests
TaegyunKwon Jan 30, 2020
8772b80
Merge branch 'watch_total' into refactoring_yj
luciaicull Jan 30, 2020
bce43c5
modify load_composer_name
luciaicull Jan 30, 2020
e063bfc
add dataset test code and merge it with original PieceData test code …
luciaicull Jan 30, 2020
1b4cf4c
Merge pull request #11 from TaegyunKwon/refactoring
jdasam Jan 30, 2020
e2175d4
Merge branch 'refactoring' into refactoring_yj
luciaicull Jan 30, 2020
55b3a82
Merge pull request #13 from luciaicull/refactoring_yj
jdasam Jan 30, 2020
376b971
Add beat-level, measure-level dynamics
jdasam Jan 31, 2020
4919310
minor - fix score features to dictionary
jdasam Jan 31, 2020
9773f72
Fix error case when composer name is not defined
jdasam Feb 1, 2020
ffeae72
Add update_dataset, fix MIDI file when Nakamura algorithm fails
jdasam Feb 3, 2020
17232d2
fix combine_wavy_line
jdasam Feb 4, 2020
e99f5fe
Fix error when there is no absolute dynamics
jdasam Feb 4, 2020
477e894
improve update_dataset
jdasam Feb 4, 2020
295e599
change default features
jdasam Feb 8, 2020
57aba0a
delete dict initialization in extract_score_features
jdasam Feb 8, 2020
e8a9e95
fix error in get_longer_level_dynamics
jdasam Feb 8, 2020
fc3780f
delete binary_index_for_edge
jdasam Feb 8, 2020
fc22992
Error fixed in get_dynamics(), rel.end_xml_position
jdasam Feb 8, 2020
ff3e199
First Version of data_for_training
jdasam Feb 8, 2020
cbe46ff
fix error
jdasam Feb 10, 2020
a1d437f
minor changes
jdasam Feb 10, 2020
6c5c1bc
remove data_structure dependency from dataset class
TaegyunKwon Feb 10, 2020
b12081b
separate DataClass and specific DataClass
TaegyunKwon Feb 11, 2020
a95a9e0
fix convert_feature_to_VirtuosoNet_format
jdasam Feb 11, 2020
0eb073d
modified testcodes, make EmotionDataset, YamahaDataset class
TaegyunKwon Feb 11, 2020
e86e817
fix load_score error, add alias attr for PieceData <-ScoreData
TaegyunKwon Feb 13, 2020
0ab85d4
add __str__ method for class
TaegyunKwon Feb 13, 2020
2b7b454
make save option
TaegyunKwon Feb 13, 2020
0dd1f28
add save option
TaegyunKwon Feb 13, 2020
b15c3ad
argparse type change for save. bool -> store true
TaegyunKwon Feb 13, 2020
dce43fe
add readme.md
TaegyunKwon Feb 13, 2020
a5e42b6
fix error in xml_direction_encoding
jdasam Feb 13, 2020
1b4b8ff
load score midi only when load performances
jdasam Feb 13, 2020
54aad15
Merge pull request #16 from jdasam/refactoring_wip
jdasam Feb 13, 2020
00542a2
Merge branch 'refactoring' into refactoring_wip
jdasam Feb 13, 2020
e5ec974
Merge pull request #18 from TaegyunKwon/refactoring_wip
jdasam Feb 13, 2020
dbf92fc
erase updates
TaegyunKwon Feb 13, 2020
8b1d809
change default action for PieceData. if save=False, if: .dat file exi…
TaegyunKwon Feb 13, 2020
aa71c9b
adapt data_for_training to new data_class format
TaegyunKwon Feb 13, 2020
ec2094e
Merge pull request #20 from TaegyunKwon/refactoring_wip
jdasam Feb 14, 2020
dea6a4f
handle errors in sibelius
jdasam Jul 20, 2020
29c0452
handle implicit measure error
jdasam Jul 23, 2020
a2109df
add read_xml only for ScoreData
jdasam Aug 16, 2020
33f8dc0
change relative import (from .) to just import, remove sudo
TaegyunKwon Sep 8, 2020
b09551e
change relative import (from .) to just import, remove sudo
TaegyunKwon Sep 8, 2020
7b92ea7
wip
Oct 31, 2020
a286fab
delete git modules
Oct 31, 2020
909132c
delete dir
Oct 31, 2020
c0abaf2
add midi_utils, musicxml_parser as a subfiles
Oct 31, 2020
fe9c82d
Merge branch 'refactoring'
TaegyunKwon Feb 16, 2021
927e459
Merge branch 'master' into center
TaegyunKwon Feb 16, 2021
b7a25a2
arrange submodules
TaegyunKwon Feb 16, 2021
a9c628d
hotfix: score_dat_path.exists() in data_class.PieceData
TaegyunKwon Feb 16, 2021
7323cb6
add pedal inf
jdasam Aug 17, 2018
87d224c
for midi cleaned. (default path changed!!)
jdasam Aug 17, 2018
9b550cb
update midi_utils
TaegyunKwon Feb 16, 2021
32d5f4e
fix merge msg err
TaegyunKwon Feb 17, 2021
017e788
change mxp url, update traceback
TaegyunKwon Feb 17, 2021
ba91340
fix merge msg err
TaegyunKwon Feb 17, 2021
645abea
update submodule
TaegyunKwon Feb 17, 2021
bf9775e
Merge branch 'tgk' into subtree_original
TaegyunKwon Feb 17, 2021
9ab6262
Add 'musicXML_parser/' from commit 'ba91340f021a6d66c78af904e458e9f95…
TaegyunKwon Feb 17, 2021
b3d1eff
Add 'midi_utils/' from commit '87d224cb057de40c3a78454ef9bc9eb0687dc3d7'
TaegyunKwon Feb 17, 2021
d28a424
rename mxp
TaegyunKwon Feb 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.DS_Store
chopin_cleaned/
mscx_files/
*.pyc
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

32 changes: 3 additions & 29 deletions binary_index.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
def binary_index(alist, item):
first = 0
last = len(alist)-1
midpoint = 0

if(item< alist[first]):
return 0

while first<last:
midpoint = (first + last)//2
currentElement = alist[midpoint]

if currentElement < item:
if alist[midpoint+1] > item:
return midpoint
else: first = midpoint +1
if first == last and alist[last] > item:
return midpoint
elif currentElement > item:
last = midpoint -1
else:
if midpoint +1 ==len(alist):
return midpoint
while alist[midpoint+1] == item:
midpoint += 1
if midpoint + 1 == len(alist):
return midpoint
return midpoint
return last
'''
move binary_index to utils.py
'''
526 changes: 526 additions & 0 deletions data_class.py

Large diffs are not rendered by default.

249 changes: 249 additions & 0 deletions data_for_training.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
import os
import random
import numpy as np
import pickle
from . import dataset_split
from pathlib import Path
from tqdm import tqdm

NORM_FEAT_KEYS = ('midi_pitch', 'duration', 'beat_importance', 'measure_length', 'qpm_primo',
'following_rest', 'distance_from_abs_dynamic', 'distance_from_recent_tempo',
'beat_tempo', 'velocity', 'onset_deviation', 'articulation', 'pedal_refresh_time',
'pedal_cut_time', 'pedal_at_start', 'pedal_at_end', 'soft_pedal',
'pedal_refresh', 'pedal_cut', 'qpm_primo')

VNET_COPY_DATA_KEYS = ('note_location', 'align_matched', 'articulation_loss_weight')
VNET_INPUT_KEYS = ('midi_pitch', 'duration', 'beat_importance', 'measure_length', 'qpm_primo',
'following_rest', 'distance_from_abs_dynamic', 'distance_from_recent_tempo',
'beat_position', 'xml_position', 'grace_order', 'preceded_by_grace_note',
'followed_by_fermata_rest', 'pitch', 'tempo', 'dynamic', 'time_sig_vec',
'slur_beam_vec', 'composer_vec', 'notation', 'tempo_primo')

VNET_OUTPUT_KEYS = ('beat_tempo', 'velocity', 'onset_deviation', 'articulation', 'pedal_refresh_time',
'pedal_cut_time', 'pedal_at_start', 'pedal_at_end', 'soft_pedal',
'pedal_refresh', 'pedal_cut', 'qpm_primo', 'beat_tempo', 'beat_dynamics',
'measure_tempo', 'measure_dynamics')


class ScorePerformPairData:
def __init__(self, piece, perform):
self.piece_path = piece.meta.xml_path
self.perform_path = perform.midi_path
self.graph_edges = piece.notes_graph
self.features = {**piece.score_features, **perform.perform_features}
self.split_type = None
self.features['num_notes'] = piece.num_notes


class PairDataset:
def __init__(self, dataset):
self.dataset_path = dataset.path
self.data_pairs = []
self.feature_stats = None
for piece in dataset.pieces:
for performance in piece.performances:
self.data_pairs.append(ScorePerformPairData(piece, performance))

def get_squeezed_features(self, target_feat_keys):
squeezed_values = dict()
for feat_type in target_feat_keys:
squeezed_values[feat_type] = []
for pair in self.data_pairs:
for feat_type in target_feat_keys:
if isinstance(pair.features[feat_type], list):
squeezed_values[feat_type] += pair.features[feat_type]
else:
squeezed_values[feat_type].append(pair.features[feat_type])
return squeezed_values

def update_mean_stds_of_entire_dataset(self, target_feat_keys=NORM_FEAT_KEYS):
squeezed_values = self.get_squeezed_features(target_feat_keys)
self.feature_stats = cal_mean_stds(squeezed_values, target_feat_keys)

def update_dataset_split_type(self, valid_set_list=dataset_split.VALID_LIST, test_set_list=dataset_split.TEST_LIST):
# TODO: the split
for pair in self.data_pairs:
path = pair.piece_path
for valid_name in valid_set_list:
if valid_name in path:
pair.split_type = 'valid'
break
else:
for test_name in test_set_list:
if test_name in path:
pair.split_type = 'test'
break

if pair.split_type is None:
pair.split_type = 'train'

def shuffle_data(self):
random.shuffle(self.data_pairs)

def save_features_for_virtuosoNet(self, save_folder):
'''
Convert features into format of VirtuosoNet training data
:return: None (save file)
'''
def _flatten_path(file_path):
return '_'.join(file_path.parts)

save_folder = Path(save_folder)
split_types = ['train', 'valid', 'test']

save_folder.mkdir()
for split in split_types:
(save_folder / split).mkdir()

training_data = []
validation_data = []
test_data = []

for pair_data in tqdm(self.data_pairs):
formatted_data = dict()
formatted_data['input_data'], formatted_data['output_data'] = convert_feature_to_VirtuosoNet_format(pair_data.features, self.feature_stats)
for key in VNET_COPY_DATA_KEYS:
formatted_data[key] = pair_data.features[key]
formatted_data['graph'] = pair_data.graph_edges
formatted_data['score_path'] = pair_data.piece_path
formatted_data['perform_path'] = pair_data.perform_path

save_name = _flatten_path(
Path(pair_data.perform_path).relative_to(Path(self.dataset_path))) + '.dat'

with open(save_folder / pair_data.split_type / save_name, "wb") as f:
pickle.dump(formatted_data, f, protocol=2)

with open(save_folder / "stat.dat", "wb") as f:
pickle.dump(self.feature_stats, f, protocol=2)


def get_feature_from_entire_dataset(dataset, target_score_features, target_perform_features):
# e.g. feature_type = ['score', 'duration'] or ['perform', 'beat_tempo']
output_values = dict()
for feat_type in (target_score_features + target_perform_features):
output_values[feat_type] = []
for piece in dataset.pieces:
for performance in piece.performances:
for feat_type in target_score_features:
# output_values[feat_type] += piece.score_features[feat_type]
output_values[feat_type].append(piece.score_features[feat_type])
for feat_type in target_perform_features:
output_values[feat_type].append(performance.perform_features[feat_type])
return output_values


def normalize_feature(data_values, target_feat_keys):
for feat in target_feat_keys:
concatenated_data = [note for perf in data_values[feat] for note in perf]
mean = sum(concatenated_data) / len(concatenated_data)
var = sum(pow(x-mean,2) for x in concatenated_data) / len(concatenated_data)
# data_values[feat] = [(x-mean) / (var ** 0.5) for x in data_values[feat]]
for i, perf in enumerate(data_values[feat]):
data_values[feat][i] = [(x-mean) / (var ** 0.5) for x in perf]

return data_values

# def combine_dict_to_array():

def cal_mean_stds_of_entire_dataset(dataset, target_features):
'''
:param dataset: DataSet class
:param target_features: list of dictionary keys of features
:return: dictionary of mean and stds
'''
output_values = dict()
for feat_type in (target_features):
output_values[feat_type] = []

for piece in dataset.pieces:
for performance in piece.performances:
for feat_type in target_features:
if feat_type in piece.score_features:
output_values[feat_type] += piece.score_features[feat_type]
elif feat_type in performance.perform_features:
output_values[feat_type] += performance.perform_features[feat_type]
else:
print('Selected feature {} is not in the data'.format(feat_type))

stats = cal_mean_stds(output_values, target_features)

return stats


def cal_mean_stds(feat_datas, target_features):
stats = dict()
for feat_type in target_features:
mean = sum(feat_datas[feat_type]) / len(feat_datas[feat_type])
var = sum((x-mean)**2 for x in feat_datas[feat_type]) / len(feat_datas[feat_type])
stds = var ** 0.5
if stds == 0:
stds = 1
stats[feat_type] = {'mean': mean, 'stds':stds}
return stats


def convert_feature_to_VirtuosoNet_format(feature_data, stats, input_keys=VNET_INPUT_KEYS, output_keys=VNET_OUTPUT_KEYS):
input_data = []
output_data = []

def check_if_global_and_normalize(key):
value = feature_data[key]
if not isinstance(value, list) or len(value) != feature_data['num_notes']: # global features like qpm_primo, tempo_primo, composer_vec
value = [value] * feature_data['num_notes']
if key in stats: # if key needs normalization,
value = [(x - stats[key]['mean']) / stats[key]['stds'] for x in value]
return value

def add_to_list(alist, item):
if isinstance(item, list):
alist += item
else:
alist.append(item)
return alist

def cal_dimension(data_with_all_features):
total_length = 0
for feat_data in data_with_all_features:
if isinstance(feat_data[0], list):
length = len(feat_data[0])
else:
length = 1
total_length += length
return total_length


for key in input_keys:
value = check_if_global_and_normalize(key)
input_data.append(value)
for key in output_keys:
value = check_if_global_and_normalize(key)
output_data.append(value)

input_dimension = cal_dimension(input_data)
output_dimension = cal_dimension(output_data)

input_array = np.zeros((feature_data['num_notes'], input_dimension))
output_array = np.zeros((feature_data['num_notes'], output_dimension))

current_idx = 0

for value in input_data:
if isinstance(value[0], list):
length = len(value[0])
input_array[:, current_idx:current_idx + length] = value
else:
length = 1
input_array[:,current_idx] = value
current_idx += length
current_idx = 0
for value in output_data:
if isinstance(value[0], list):
length = len(value[0])
output_array[:, current_idx:current_idx + length] = value
else:
length = 1
output_array[:,current_idx] = value
current_idx += length

return input_array, output_array
Loading