diff --git a/README.md b/README.md index bc5c32d..2a3809c 100644 --- a/README.md +++ b/README.md @@ -34,13 +34,30 @@ The toolbox propose a set of musically informed objective measures to obtain ana 3. Note length histogram: To extract the note length histogram, we first define a set of allowable beat length classes [full, half, quarter, 8th, 16th, dot half, dot quarter, dot 8th, dot 16th, half note triplet, quarter note triplet, 8th note triplet]. The rest option, when activated, will double the vector size to represent the same lengths for rests. The classification of each event is performed by dividing the basic unit into the length of (barlength)/96, and each note length is quantized to the closest length category. The output vector has a length of either 12 or 24, respectively. 4. Note length transition matrix: Similar to the pitch class transition matrix, the note length tran- sition matrix provides useful information for rhythm description. The output feature dimension is 12 × 12 or 24 × 24, respectively. -### Dependency +### Dependencies +--- * [`scipy`](http://www.scipy.org/) * [`numpy`](http://www.numpy.org) * [`pretty-midi`](https://github.com/craffel/pretty-midi) * [`python-midi`](https://github.com/vishnubob/python-midi) * [`sklearn`](https://scikit-learn.org/stable/) - ### To use - Detailed documentation included [here](https://github.com/RichardYang40148/mgeval/blob/master/mgeval/documentation.md). - - Demonstration of metrics included in [demo.ipynb](https://github.com/RichardYang40148/mgeval/commits?author=RichardYang40148) + * [`pickle`](https://docs.python.org/3/library/pickle.html) (optional) + +### To use +--- + +#### Library Reference + +Detailed documentation included [here](https://github.com/RichardYang40148/mgeval/blob/master/mgeval/documentation.md). + +Demonstration of metrics included in [demo.ipynb](https://github.com/RichardYang40148/mgeval/commits?author=RichardYang40148) + +#### Standalone Module + +You can run mgeval as a standalone module with the following command on the root directory: + +```shell +python . +``` + +Provided both directories exist and contain valid MIDI files, this script calculates all available metrics for each set and save the result to `output_filename`, as a pickle. diff --git a/__main__.py b/__main__.py index 81effa4..2c12208 100644 --- a/__main__.py +++ b/__main__.py @@ -9,8 +9,6 @@ import pretty_midi from pprint import pprint import pickle -# import seaborn as sns -# import matplotlib.pyplot as plt from mgeval import core, utils from sklearn.model_selection import LeaveOneOut @@ -30,9 +28,18 @@ set1 = glob.glob(os.path.join(args.set1dir, '*')) set2 = glob.glob(os.path.join(args.set2dir, '*')) +print('Evaluation sets (sample and baseline):') print(set1) print(set2) +if not any(set1): + print("Error: sample set it empty") + exit() + +if not any(set2): + print("Error: baseline set it empty") + exit() + # Initialize Evaluation Set num_samples = min(len(set2), len(set1)) diff --git a/mgeval/core.py b/mgeval/core.py index 3430e0b..316055c 100644 --- a/mgeval/core.py +++ b/mgeval/core.py @@ -217,9 +217,7 @@ def bar_pitch_class_histogram(self, feature, track_num=1, num_bar=None, bpm=120) if actual_bar > num_bar: mod = np.mod(len(piano_roll), bar_length*128) - piano_roll = piano_roll[:-mod] - piano_roll = piano_roll.reshape((num_bar, -1, 128)) # make exact bar - # piano_roll = piano_roll[:-np.mod(len(piano_roll), bar_length)] + piano_roll = piano_roll[:-np.mod(len(piano_roll), bar_length)].reshape((num_bar, -1, 128)) # make exact bar elif actual_bar == num_bar: piano_roll = piano_roll.reshape((num_bar, -1, 128)) else: diff --git a/mgeval/core.pyc b/mgeval/core.pyc index fca7656..ccfe409 100644 Binary files a/mgeval/core.pyc and b/mgeval/core.pyc differ