-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.py
More file actions
36 lines (29 loc) · 1.16 KB
/
Copy pathloader.py
File metadata and controls
36 lines (29 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import re
import pathlib
import constants as const
import librosa as libr
import numpy as np
class ZFinchDataset():
def __init__(self, adult_paths):
self.adult_paths = list(pathlib.Path(adult_paths).iterdir())
self.adult_examples = [to_example(path) for path in self.adult_paths]
self.examples = self.adult_examples
class ZFinchExample:
def __init__(self, path, name, date, call_type, rendition_num):
self.path = path
self.name = name
self.date = date
self.call_type = call_type
self.rendition_num = rendition_num
def __str__(self):
return "name: {}, date: {}, call_type: {}, rendition_num: {}".format(
self.name, self.date, self.call_type, self.rendition_num)
def to_example(path):
name, date, call_type, rendition_num = re.match(const.FILE_NAME_PATTERN, path.name).groups()
return ZFinchExample(path, name, date, call_type, rendition_num)
def load_dataset():
return ZFinchDataset(const.ADULT_RECORDINGS_PATH)
def load_data_trf(dir):
paths = list(pathlib.Path(dir).iterdir())
ds = [libr.load(path)[0] for path in paths]
return np.array(ds)