yangwang825 commited on
Commit
6656c43
·
verified ·
1 Parent(s): 933e7d1

Update ravdess-script.py

Browse files
Files changed (1) hide show
  1. ravdess-script.py +20 -29
ravdess-script.py CHANGED
@@ -92,16 +92,7 @@ class RAVDESS(datasets.GeneratorBasedBuilder):
92
  def _split_generators(self, dl_manager):
93
  """Returns SplitGenerators."""
94
  archive_path = dl_manager.extract(_COMPRESSED_FILENAME)
95
- return [
96
- datasets.SplitGenerator(
97
- name=datasets.Split.TRAIN, gen_kwargs={"archive_path": archive_path, "split": "train"}
98
- ),
99
- datasets.SplitGenerator(
100
- name=datasets.Split.TEST, gen_kwargs={"archive_path": archive_path, "split": "test"}
101
- ),
102
- ]
103
 
104
- def _generate_examples(self, archive_path, split=None):
105
  extensions = ['.wav']
106
  _, _walker = fast_scandir(archive_path, extensions, recursive=True)
107
  _walker_with_fold = [(fileid, default_find_fold(fileid)) for fileid in _walker]
@@ -122,27 +113,27 @@ class RAVDESS(datasets.GeneratorBasedBuilder):
122
  train_fold = ['1', '2', '3', '4']
123
  test_fold = ['5']
124
 
125
- if split == 'train':
126
- train_walker = [fileid for fileid, fold in _walker_with_fold if fold in train_fold]
127
- for guid, audio_path in enumerate(train_walker):
128
- yield guid, {
129
- "id": str(guid),
130
- "file": audio_path,
131
- "audio": audio_path,
132
- "emotion": default_find_classes(audio_path),
133
- "label": default_find_classes(audio_path),
134
- }
135
- elif split == 'test':
136
- test_walker = [fileid for fileid, fold in _walker_with_fold if fold in train_fold]
137
- for guid, audio_path in enumerate(test_walker):
138
- yield guid, {
139
- "id": str(guid),
140
- "file": audio_path,
141
- "audio": audio_path,
142
- "emotion": default_find_classes(audio_path),
143
- "label": default_find_classes(audio_path),
144
- }
145
 
 
 
 
 
 
 
 
 
 
146
 
147
  def default_find_classes(audio_path):
148
  return RAVDESS_EMOTIONS_MAPPING.get(Path(audio_path).name.split('-')[2])
 
92
  def _split_generators(self, dl_manager):
93
  """Returns SplitGenerators."""
94
  archive_path = dl_manager.extract(_COMPRESSED_FILENAME)
 
 
 
 
 
 
 
 
95
 
 
96
  extensions = ['.wav']
97
  _, _walker = fast_scandir(archive_path, extensions, recursive=True)
98
  _walker_with_fold = [(fileid, default_find_fold(fileid)) for fileid in _walker]
 
113
  train_fold = ['1', '2', '3', '4']
114
  test_fold = ['5']
115
 
116
+ train_walker = [fileid for fileid, fold in _walker_with_fold if fold in train_fold]
117
+ test_walker = [fileid for fileid, fold in _walker_with_fold if fold in train_fold]
118
+
119
+ return [
120
+ datasets.SplitGenerator(
121
+ name=datasets.Split.TRAIN, gen_kwargs={"audio_paths": train_walker, "split": "train"}
122
+ ),
123
+ datasets.SplitGenerator(
124
+ name=datasets.Split.TEST, gen_kwargs={"audio_paths": test_walker, "split": "test"}
125
+ ),
126
+ ]
 
 
 
 
 
 
 
 
 
127
 
128
+ def _generate_examples(self, audio_paths, split=None):
129
+ for guid, audio_path in enumerate(audio_paths):
130
+ yield guid, {
131
+ "id": str(guid),
132
+ "file": audio_path,
133
+ "audio": audio_path,
134
+ "emotion": default_find_classes(audio_path),
135
+ "label": default_find_classes(audio_path),
136
+ }
137
 
138
  def default_find_classes(audio_path):
139
  return RAVDESS_EMOTIONS_MAPPING.get(Path(audio_path).name.split('-')[2])