salu133445 / muspy

A toolkit for symbolic music generation
https://salu133445.github.io/muspy/
MIT License
435 stars 51 forks source link

Failed to add annotation when adding a new dataset #62

Closed annahung31 closed 3 years ago

annahung31 commented 3 years ago

Hi,

I'm adding a new dataset that contains midi files and their emotion labels. About the emotion labels, I try to follow the way that HaydnOp20 did:

  1. write a function get_annotations to extract the annotation.
  2. add the annotation in the original read function

However, when I call the class, the annotations are still []. Is there anything I missed? Thanks!

My dataset class

class EMOPIADataset(RemoteFolderDataset):
    """EMOPIA Dataset."""

    _info = DatasetInfo(_NAME, _DESCRIPTION, _HOMEPAGE, _LICENSE)
    _citation = _CITATION
    _sources = {
        "emopia": {
            "filename": "EMOPIA_1.0.zip",
            "url": "https://zenodo.org/record/5090631/files/EMOPIA_1.0.zip",
            "archive": True,
            #"size": ,
            #"md5": "",
            #"sha256": "",
        }
    }

    _extension = "mid"

    def read(self, filename: Union[str, Path]) -> Music:

        """Read a file into a Music object."""
        music = read_midi(self.root / filename)
        annotations = get_annotations(filename)
        music.annotations = annotations
        return music

def get_annotations(filename: str) -> List[Annotation]:
    """return the emotion class as an annotation object"""

    annotations = []
    annotation = {
            "emo_class": filename[1],
            "YouTube_ID": filename[3:14],
            "seg_id": filename.split('_')[-1]

    }
    annotations.append(Annotation(annotation=annotation))
    return annotations

How I call the dataset

emopia = muspy.EMOPIADataset("data/emopia/", download_and_extract=True)
emopia.convert()
music = emopia[0]

Expected result

music.annotations 
>>> [Annotation(annotation={
'emo_class': 1,
'YouTube_ID':...
})]

Current result

music.annotations
>>> []
salu133445 commented 3 years ago

Hi,

It should be annotations.append(Annotation(time=0, annotation=annotation)) rather than annotations.append(Annotation(annotation=annotation)) as time is a required attribute for Annotation class.

For debugging, you could do music = emopia[0] before converting it as ignore_exceptions is set to True by default in convert function.

Thanks!

annahung31 commented 3 years ago

Got it, thanks!