added embeddings and feature "domain"
Browse files- README.md +40 -50
- data/dev_metadata.csv +2 -2
- data/dev_test.tar.gz +2 -2
- data/dev_train.tar.gz +2 -2
- dcase23-task2-enriched.py +93 -9
README.md
CHANGED
@@ -70,30 +70,16 @@ pip install renumics-spotlight
|
|
70 |
|
71 |
and simply run the following codeblock:
|
72 |
```jupyterpython
|
73 |
-
from datasets import load_dataset
|
74 |
-
from renumics import spotlight
|
75 |
-
|
76 |
-
ds = load_dataset("renumics/dcase23-task2-enriched", "dev")
|
77 |
-
df = ds.to_pandas()
|
78 |
-
spotlight.show(df, dtype={'path': spotlight.Audio})
|
79 |
-
```
|
80 |
-
|
81 |
-
to load a more advanced view, we can utilize spotlight's layout function and add clear names for the machine_types in the dataset.
|
82 |
-
```jupyterpython
|
83 |
-
import pandas as pd
|
84 |
from datasets import load_dataset, load_dataset_builder
|
85 |
from renumics import spotlight
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
db = load_dataset_builder("renumics/dcase23-task2-enriched", "dev")
|
90 |
|
91 |
-
df =
|
92 |
-
spotlight.show(df, dtype={'audio': spotlight.Audio}, layout=db.config.get_layout())
|
93 |
```
|
94 |
|
95 |
-
[//]: # (todo: add embeddings column)
|
96 |
-
|
97 |
## Dataset Structure
|
98 |
|
99 |
### Data Instances
|
@@ -104,9 +90,9 @@ a ClassLabel for the label and a ClassLabel for the class.
|
|
104 |
```
|
105 |
{'audio': {'array': array([ 0. , 0.00024414, -0.00024414, ..., -0.00024414,
|
106 |
0. , 0. ], dtype=float32),
|
107 |
-
|
108 |
-
|
109 |
-
}
|
110 |
'path': 'train/fan_section_01_source_train_normal_0592_f-n_A.wav'
|
111 |
'section': 1
|
112 |
'd1p': 'f-n'
|
@@ -118,6 +104,9 @@ a ClassLabel for the label and a ClassLabel for the class.
|
|
118 |
'domain': 0 (source)
|
119 |
'label': 0 (normal)
|
120 |
'class': 1 (fan)
|
|
|
|
|
|
|
121 |
}
|
122 |
```
|
123 |
|
@@ -125,16 +114,15 @@ The length of each audio file is 10 seconds.
|
|
125 |
|
126 |
### Data Fields
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
- `audio`:
|
131 |
- `path`: a string representing the path of the audio file inside the _tar.gz._-archive.
|
132 |
-
- `section`: an integer
|
133 |
-
- `d*p`:
|
134 |
-
- `d*v`:
|
135 |
-
- `domain`:
|
136 |
-
- `class`:
|
137 |
- `label`: an integer whose value may be either _0_, indicating that the audio sample is _normal_, _1_, indicating that the audio sample contains an _anomaly_.
|
|
|
138 |
|
139 |
### Data Splits
|
140 |
|
@@ -149,6 +137,8 @@ The information for the evaluation dataset will follow after release.
|
|
149 |
|
150 |
## Dataset Creation
|
151 |
|
|
|
|
|
152 |
### Curation Rationale
|
153 |
|
154 |
This dataset is the "development dataset" for the [DCASE 2023 Challenge Task 2 "First-Shot Unsupervised Anomalous Sound Detection for Machine Condition Monitoring"](https://dcase.community/challenge2023/task-unsupervised-anomalous-sound-detection-for-machine-condition-monitoring).
|
@@ -163,7 +153,26 @@ The data consists of the normal/anomalous operating sounds of seven types of rea
|
|
163 |
- Slide rail
|
164 |
- Valve
|
165 |
|
166 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
Anomalous sound detection (ASD) is the task of identifying whether the sound emitted from a target machine is normal or anomalous. Automatic detection of mechanical failure is an essential technology in the fourth industrial revolution, which involves artificial-intelligence-based factory automation. Prompt detection of machine anomalies by observing sounds is useful for monitoring the condition of machines.
|
169 |
|
@@ -185,25 +194,6 @@ For a completely new machine type, hyperparameters of the trained model cannot b
|
|
185 |
|
186 |
While sounds from multiple machines of the same machine type can be used to enhance detection performance, it is often the case that sound data from only one machine are available for a machine type. In such a case, the system should be able to train models using only one machine from a machine type.
|
187 |
|
188 |
-
### Source Data
|
189 |
-
|
190 |
-
#### Definition
|
191 |
-
|
192 |
-
We first define key terms in this task: "machine type," "section," "source domain," "target domain," and "attributes.".
|
193 |
-
|
194 |
-
- "Machine type" indicates the type of machine, which in the development dataset is one of seven: fan, gearbox, bearing, slide rail, valve, ToyCar, and ToyTrain.
|
195 |
-
- A section is defined as a subset of the dataset for calculating performance metrics.
|
196 |
-
- The source domain is the domain under which most of the training data and some of the test data were recorded, and the target domain is a different set of domains under which some of the training data and some of the test data were recorded. There are differences between the source and target domains in terms of operating speed, machine load, viscosity, heating temperature, type of environmental noise, signal-to-noise ratio, etc.
|
197 |
-
- Attributes are parameters that define states of machines or types of noise.
|
198 |
-
|
199 |
-
#### Description
|
200 |
-
|
201 |
-
This dataset consists of seven machine types. For each machine type, one section is provided, and the section is a complete set of training and test data. For each section, this dataset provides (i) 990 clips of normal sounds in the source domain for training, (ii) ten clips of normal sounds in the target domain for training, and (iii) 100 clips each of normal and anomalous sounds for the test. The source/target domain of each sample is provided. Additionally, the attributes of each sample in the training and test data are provided in the file names and attribute csv files.
|
202 |
-
|
203 |
-
#### Recording procedure
|
204 |
-
|
205 |
-
Normal/anomalous operating sounds of machines and its related equipment are recorded. Anomalous sounds were collected by deliberately damaging target machines. For simplifying the task, we use only the first channel of multi-channel recordings; all recordings are regarded as single-channel recordings of a fixed microphone. We mixed a target machine sound with environmental noise, and only noisy recordings are provided as training/test data. The environmental noise samples were recorded in several real factory environments. We will publish papers on the dataset to explain the details of the recording procedure by the submission deadline.
|
206 |
-
|
207 |
## Considerations for Using the Data
|
208 |
|
209 |
### Social Impact of Dataset
|
@@ -262,4 +252,4 @@ If you use this dataset, please cite all the following papers. We will publish a
|
|
262 |
doi = {10.5281/zenodo.7687464},
|
263 |
url = {https://doi.org/10.5281/zenodo.7687464}
|
264 |
}
|
265 |
-
```
|
|
|
70 |
|
71 |
and simply run the following codeblock:
|
72 |
```jupyterpython
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
from datasets import load_dataset, load_dataset_builder
|
74 |
from renumics import spotlight
|
75 |
|
76 |
+
ds = load_dataset("dcase23-task2-enriched.py", "dev", split="all", streaming=False)
|
77 |
+
db = load_dataset_builder("dcase23-task2-enriched.py", "dev")
|
|
|
78 |
|
79 |
+
df = db.config.to_spotlight(ds)
|
80 |
+
spotlight.show(df, dtype={'audio': spotlight.Audio, "ast-finetuned-audioset-10-10-0.4593-embeddings": spotlight.Embedding}, layout=db.config.get_layout())
|
81 |
```
|
82 |
|
|
|
|
|
83 |
## Dataset Structure
|
84 |
|
85 |
### Data Instances
|
|
|
90 |
```
|
91 |
{'audio': {'array': array([ 0. , 0.00024414, -0.00024414, ..., -0.00024414,
|
92 |
0. , 0. ], dtype=float32),
|
93 |
+
'path': 'train/fan_section_01_source_train_normal_0592_f-n_A.wav',
|
94 |
+
'sampling_rate': 16000
|
95 |
+
}
|
96 |
'path': 'train/fan_section_01_source_train_normal_0592_f-n_A.wav'
|
97 |
'section': 1
|
98 |
'd1p': 'f-n'
|
|
|
104 |
'domain': 0 (source)
|
105 |
'label': 0 (normal)
|
106 |
'class': 1 (fan)
|
107 |
+
'ast-finetuned-audioset-10-10-0.4593-embeddings': [[0.8152204155921936,
|
108 |
+
1.5862374305725098, ...,
|
109 |
+
1.7154160737991333]]
|
110 |
}
|
111 |
```
|
112 |
|
|
|
114 |
|
115 |
### Data Fields
|
116 |
|
117 |
+
- `audio`: an `datasets.Audio`
|
|
|
|
|
118 |
- `path`: a string representing the path of the audio file inside the _tar.gz._-archive.
|
119 |
+
- `section`: an integer representing the section, see [Definition](#Description)
|
120 |
+
- `d*p`: a string representing the name of the d*-parameter
|
121 |
+
- `d*v`: a string representing the value of the corresponding d*-parameter
|
122 |
+
- `domain`: an integer whose value may be either _0_, indicating that the audio sample is from the _source_ domain, _1_, indicating that the audio sample is from the _target_.
|
123 |
+
- `class`: an integer as class label.
|
124 |
- `label`: an integer whose value may be either _0_, indicating that the audio sample is _normal_, _1_, indicating that the audio sample contains an _anomaly_.
|
125 |
+
- `ast-finetuned-audioset-10-10-0.4593-embeddings`: an `datasets.Array2D` representing audio embeddings that are generated with the [Audio Spectrogram Transformer](https://huggingface.co/docs/transformers/model_doc/audio-spectrogram-transformer#transformers.ASTFeatureExtractor).
|
126 |
|
127 |
### Data Splits
|
128 |
|
|
|
137 |
|
138 |
## Dataset Creation
|
139 |
|
140 |
+
The following information is copied from the original [dataset upload on zenodo.org](https://zenodo.org/record/7690148#.ZAXsSdLMLmE)
|
141 |
+
|
142 |
### Curation Rationale
|
143 |
|
144 |
This dataset is the "development dataset" for the [DCASE 2023 Challenge Task 2 "First-Shot Unsupervised Anomalous Sound Detection for Machine Condition Monitoring"](https://dcase.community/challenge2023/task-unsupervised-anomalous-sound-detection-for-machine-condition-monitoring).
|
|
|
153 |
- Slide rail
|
154 |
- Valve
|
155 |
|
156 |
+
### Source Data
|
157 |
+
|
158 |
+
#### Definition
|
159 |
+
|
160 |
+
We first define key terms in this task: "machine type," "section," "source domain," "target domain," and "attributes.".
|
161 |
+
|
162 |
+
- "Machine type" indicates the type of machine, which in the development dataset is one of seven: fan, gearbox, bearing, slide rail, valve, ToyCar, and ToyTrain.
|
163 |
+
- A section is defined as a subset of the dataset for calculating performance metrics.
|
164 |
+
- The source domain is the domain under which most of the training data and some of the test data were recorded, and the target domain is a different set of domains under which some of the training data and some of the test data were recorded. There are differences between the source and target domains in terms of operating speed, machine load, viscosity, heating temperature, type of environmental noise, signal-to-noise ratio, etc.
|
165 |
+
- Attributes are parameters that define states of machines or types of noise.
|
166 |
+
|
167 |
+
#### Description
|
168 |
+
|
169 |
+
This dataset consists of seven machine types. For each machine type, one section is provided, and the section is a complete set of training and test data. For each section, this dataset provides (i) 990 clips of normal sounds in the source domain for training, (ii) ten clips of normal sounds in the target domain for training, and (iii) 100 clips each of normal and anomalous sounds for the test. The source/target domain of each sample is provided. Additionally, the attributes of each sample in the training and test data are provided in the file names and attribute csv files.
|
170 |
+
|
171 |
+
#### Recording procedure
|
172 |
+
|
173 |
+
Normal/anomalous operating sounds of machines and its related equipment are recorded. Anomalous sounds were collected by deliberately damaging target machines. For simplifying the task, we use only the first channel of multi-channel recordings; all recordings are regarded as single-channel recordings of a fixed microphone. We mixed a target machine sound with environmental noise, and only noisy recordings are provided as training/test data. The environmental noise samples were recorded in several real factory environments. We will publish papers on the dataset to explain the details of the recording procedure by the submission deadline.
|
174 |
+
|
175 |
+
### Supported Tasks and Leaderboards
|
176 |
|
177 |
Anomalous sound detection (ASD) is the task of identifying whether the sound emitted from a target machine is normal or anomalous. Automatic detection of mechanical failure is an essential technology in the fourth industrial revolution, which involves artificial-intelligence-based factory automation. Prompt detection of machine anomalies by observing sounds is useful for monitoring the condition of machines.
|
178 |
|
|
|
194 |
|
195 |
While sounds from multiple machines of the same machine type can be used to enhance detection performance, it is often the case that sound data from only one machine are available for a machine type. In such a case, the system should be able to train models using only one machine from a machine type.
|
196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
## Considerations for Using the Data
|
198 |
|
199 |
### Social Impact of Dataset
|
|
|
252 |
doi = {10.5281/zenodo.7687464},
|
253 |
url = {https://doi.org/10.5281/zenodo.7687464}
|
254 |
}
|
255 |
+
```
|
data/dev_metadata.csv
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:013c511f2e63467d9c40a73241ae6d235204a8d70a600115a78894f8ce872528
|
3 |
+
size 884134
|
data/dev_test.tar.gz
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fbe71bfc8cf7d48a6909ec890df02217dcd05361b209a05cf3b36e74386de9ab
|
3 |
+
size 364525257
|
data/dev_train.tar.gz
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:91ea5403dae9a1ff6c936fa6b55ee240897cfa591dfba9e099cbde2862b1a05c
|
3 |
+
size 1830365732
|
dcase23-task2-enriched.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import datasets
|
3 |
import datasets.info
|
4 |
import pandas as pd
|
|
|
5 |
from pathlib import Path
|
6 |
from datasets import load_dataset
|
7 |
from typing import Iterable, Dict, Optional, Union, List
|
@@ -49,6 +50,38 @@ DATA_URLS = {
|
|
49 |
"test": "data/dev_test.tar.gz",
|
50 |
"metadata": "data/dev_metadata.csv",
|
51 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
}
|
53 |
|
54 |
STATS = {
|
@@ -60,11 +93,25 @@ STATS = {
|
|
60 |
'homepage': "https://zenodo.org/record/7687464#.ZABmANLMLmH",
|
61 |
"splits": ["train", "test"],
|
62 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
}
|
65 |
|
66 |
DATASET = {
|
67 |
'dev': 'DCASE 2023 Challenge Task 2 Development Dataset',
|
|
|
|
|
68 |
}
|
69 |
|
70 |
_SPOTLIGHT_LAYOUT = "data/config-spotlight-layout.json"
|
@@ -82,6 +129,7 @@ class DCASE2023Task2DatasetConfig(datasets.BuilderConfig):
|
|
82 |
self.release_date = kwargs.pop("release_date", None)
|
83 |
self.homepage = kwargs.pop("homepage", None)
|
84 |
self.data_urls = kwargs.pop("data_urls", None)
|
|
|
85 |
self.splits = kwargs.pop("splits", None)
|
86 |
self.rename = kwargs.pop("rename", None)
|
87 |
self.layout = kwargs.pop("layout", None)
|
@@ -98,13 +146,38 @@ class DCASE2023Task2DatasetConfig(datasets.BuilderConfig):
|
|
98 |
)
|
99 |
|
100 |
def to_spotlight(self, data: Union[pd.DataFrame, datasets.Dataset]) -> pd.DataFrame:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
if type(data) == datasets.Dataset:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
df = data.to_pandas()
|
103 |
-
df["split"] = data.split
|
104 |
df["config"] = data.config_name
|
105 |
|
|
|
106 |
class_names = data.features["class"].names
|
107 |
df["class_name"] = df["class"].apply(lambda x: class_names[x])
|
|
|
|
|
|
|
|
|
108 |
elif type(data) == pd.DataFrame:
|
109 |
df = data
|
110 |
else:
|
@@ -123,7 +196,7 @@ class DCASE2023Task2Dataset(datasets.GeneratorBasedBuilder):
|
|
123 |
"""Dataset for the DCASE 2023 Challenge Task 2 "First-Shot Unsupervised Anomalous Sound Detection
|
124 |
for Machine Condition Monitoring"."""
|
125 |
|
126 |
-
VERSION = datasets.Version("0.0.
|
127 |
|
128 |
DEFAULT_CONFIG_NAME = "dev"
|
129 |
|
@@ -143,8 +216,7 @@ class DCASE2023Task2Dataset(datasets.GeneratorBasedBuilder):
|
|
143 |
]
|
144 |
|
145 |
def _info(self):
|
146 |
-
features =
|
147 |
-
{
|
148 |
"audio": datasets.Audio(sampling_rate=16_000),
|
149 |
"path": datasets.Value("string"),
|
150 |
"section": datasets.Value("int64"),
|
@@ -154,10 +226,14 @@ class DCASE2023Task2Dataset(datasets.GeneratorBasedBuilder):
|
|
154 |
"d2v": datasets.Value("string"),
|
155 |
"d3p": datasets.Value("string"),
|
156 |
"d3v": datasets.Value("string"),
|
|
|
157 |
"label": datasets.ClassLabel(num_classes=_NUM_TARGETS, names=_TARGET_NAMES),
|
158 |
"class": datasets.ClassLabel(num_classes=_NUM_CLASSES, names=_CLASS_NAMES),
|
159 |
}
|
160 |
-
|
|
|
|
|
|
|
161 |
|
162 |
return datasets.DatasetInfo(
|
163 |
# This is the description that will appear on the datasets page.
|
@@ -178,11 +254,15 @@ class DCASE2023Task2Dataset(datasets.GeneratorBasedBuilder):
|
|
178 |
audio_path = {}
|
179 |
local_extracted_archive = {}
|
180 |
split_type = {"train": datasets.Split.TRAIN, "test": datasets.Split.TEST}
|
|
|
181 |
|
182 |
for split in split_type:
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
186 |
|
187 |
return [
|
188 |
datasets.SplitGenerator(
|
@@ -191,9 +271,10 @@ class DCASE2023Task2Dataset(datasets.GeneratorBasedBuilder):
|
|
191 |
"split": split,
|
192 |
"local_extracted_archive": local_extracted_archive[split],
|
193 |
"audio_files": dl_manager.iter_archive(audio_path[split]),
|
|
|
194 |
"metadata_file": dl_manager.download_and_extract(self.config.data_urls["metadata"]),
|
195 |
},
|
196 |
-
) for split in split_type
|
197 |
]
|
198 |
|
199 |
def _generate_examples(
|
@@ -201,6 +282,7 @@ class DCASE2023Task2Dataset(datasets.GeneratorBasedBuilder):
|
|
201 |
split: str,
|
202 |
local_extracted_archive: Union[Dict, List],
|
203 |
audio_files: Optional[Iterable],
|
|
|
204 |
metadata_file: Optional[str],
|
205 |
):
|
206 |
"""Yields examples."""
|
@@ -215,6 +297,8 @@ class DCASE2023Task2Dataset(datasets.GeneratorBasedBuilder):
|
|
215 |
audio = {"path": path, "bytes": f.read()}
|
216 |
result = {field: None for field in data_fields}
|
217 |
result.update(metadata[metadata["path"] == lookup].T.squeeze().to_dict())
|
|
|
|
|
218 |
result["path"] = path
|
219 |
yield id_, {**result, "audio": audio}
|
220 |
id_ += 1
|
|
|
2 |
import datasets
|
3 |
import datasets.info
|
4 |
import pandas as pd
|
5 |
+
import numpy as np
|
6 |
from pathlib import Path
|
7 |
from datasets import load_dataset
|
8 |
from typing import Iterable, Dict, Optional, Union, List
|
|
|
50 |
"test": "data/dev_test.tar.gz",
|
51 |
"metadata": "data/dev_metadata.csv",
|
52 |
},
|
53 |
+
"add": {
|
54 |
+
"train": "data/add_train.tar.gz",
|
55 |
+
"test": "data/add_test.tar.gz",
|
56 |
+
"metadata": "data/add_metadata.csv",
|
57 |
+
},
|
58 |
+
"eval": {
|
59 |
+
"test": "data/eval_test.tar.gz",
|
60 |
+
"metadata": "data/eval_metadata.csv",
|
61 |
+
},
|
62 |
+
}
|
63 |
+
|
64 |
+
EMBEDDING_URLS = {
|
65 |
+
"dev": {
|
66 |
+
"ast-finetuned-audioset-10-10-0.4593-embeddings": {
|
67 |
+
"train": "data/MIT_ast-finetuned-audioset-10-10-0.4593-embeddings_dev_train.npz",
|
68 |
+
"test": "data/MIT_ast-finetuned-audioset-10-10-0.4593-embeddings_dev_test.npz",
|
69 |
+
"size": (1, 768),
|
70 |
+
"dtype": "float32",
|
71 |
+
},
|
72 |
+
},
|
73 |
+
"add": {
|
74 |
+
"ast-finetuned-audioset-10-10-0.4593-embeddings": {
|
75 |
+
"train": "",
|
76 |
+
"test": "",
|
77 |
+
},
|
78 |
+
},
|
79 |
+
"eval": {
|
80 |
+
"ast-finetuned-audioset-10-10-0.4593-embeddings": {
|
81 |
+
"train": "",
|
82 |
+
"test": "",
|
83 |
+
},
|
84 |
+
},
|
85 |
}
|
86 |
|
87 |
STATS = {
|
|
|
93 |
'homepage': "https://zenodo.org/record/7687464#.ZABmANLMLmH",
|
94 |
"splits": ["train", "test"],
|
95 |
},
|
96 |
+
# 'add': {
|
97 |
+
# 'date': None,
|
98 |
+
# 'version': "0.0.0",
|
99 |
+
# 'homepage': None,
|
100 |
+
# "splits": ["train", "test"],
|
101 |
+
# },
|
102 |
+
# 'eval': {
|
103 |
+
# 'date': None,
|
104 |
+
# 'version': "0.0.0",
|
105 |
+
# 'homepage': None,
|
106 |
+
# "splits": ["test"],
|
107 |
+
# },
|
108 |
}
|
109 |
}
|
110 |
|
111 |
DATASET = {
|
112 |
'dev': 'DCASE 2023 Challenge Task 2 Development Dataset',
|
113 |
+
'add': 'DCASE 2023 Challenge Task 2 Additional Train Dataset',
|
114 |
+
'eval': 'DCASE 2023 Challenge Task 2 Evaluation Dataset',
|
115 |
}
|
116 |
|
117 |
_SPOTLIGHT_LAYOUT = "data/config-spotlight-layout.json"
|
|
|
129 |
self.release_date = kwargs.pop("release_date", None)
|
130 |
self.homepage = kwargs.pop("homepage", None)
|
131 |
self.data_urls = kwargs.pop("data_urls", None)
|
132 |
+
self.embeddings_urls = kwargs.pop("embeddings_urls", None)
|
133 |
self.splits = kwargs.pop("splits", None)
|
134 |
self.rename = kwargs.pop("rename", None)
|
135 |
self.layout = kwargs.pop("layout", None)
|
|
|
146 |
)
|
147 |
|
148 |
def to_spotlight(self, data: Union[pd.DataFrame, datasets.Dataset]) -> pd.DataFrame:
|
149 |
+
|
150 |
+
def get_split(path: str) -> str:
|
151 |
+
fn = os.path.basename(path)
|
152 |
+
if "train" in fn:
|
153 |
+
return "train"
|
154 |
+
elif "test" in fn:
|
155 |
+
return "test"
|
156 |
+
else:
|
157 |
+
raise NotImplementedError
|
158 |
+
|
159 |
if type(data) == datasets.Dataset:
|
160 |
+
# remove embedding columns first -> throws error in .to_pandas()
|
161 |
+
embeddings = {}
|
162 |
+
emb_features = [key for key, val in data.features.items() if type(val) == datasets.Array2D]
|
163 |
+
if len(emb_features) > 0:
|
164 |
+
embeddings = {
|
165 |
+
key: [np.asarray(emb).reshape(-1,) for emb in data[key].copy()] for key in emb_features
|
166 |
+
}
|
167 |
+
data = data.remove_columns(emb_features)
|
168 |
+
|
169 |
+
# retrieve split
|
170 |
df = data.to_pandas()
|
171 |
+
df["split"] = data.split._name if "+" not in data.split._name else df["path"].map(get_split)
|
172 |
df["config"] = data.config_name
|
173 |
|
174 |
+
# get clearnames for classes
|
175 |
class_names = data.features["class"].names
|
176 |
df["class_name"] = df["class"].apply(lambda x: class_names[x])
|
177 |
+
|
178 |
+
# append embeddings
|
179 |
+
for emb_name, emb_list in embeddings.items():
|
180 |
+
df[emb_name] = emb_list
|
181 |
elif type(data) == pd.DataFrame:
|
182 |
df = data
|
183 |
else:
|
|
|
196 |
"""Dataset for the DCASE 2023 Challenge Task 2 "First-Shot Unsupervised Anomalous Sound Detection
|
197 |
for Machine Condition Monitoring"."""
|
198 |
|
199 |
+
VERSION = datasets.Version("0.0.3")
|
200 |
|
201 |
DEFAULT_CONFIG_NAME = "dev"
|
202 |
|
|
|
216 |
]
|
217 |
|
218 |
def _info(self):
|
219 |
+
features = {
|
|
|
220 |
"audio": datasets.Audio(sampling_rate=16_000),
|
221 |
"path": datasets.Value("string"),
|
222 |
"section": datasets.Value("int64"),
|
|
|
226 |
"d2v": datasets.Value("string"),
|
227 |
"d3p": datasets.Value("string"),
|
228 |
"d3v": datasets.Value("string"),
|
229 |
+
"domain": datasets.ClassLabel(num_classes=2, names=["source", "target"]),
|
230 |
"label": datasets.ClassLabel(num_classes=_NUM_TARGETS, names=_TARGET_NAMES),
|
231 |
"class": datasets.ClassLabel(num_classes=_NUM_CLASSES, names=_CLASS_NAMES),
|
232 |
}
|
233 |
+
features.update({
|
234 |
+
emb_name: datasets.Array2D(shape=emb["size"], dtype=emb["dtype"]) for emb_name, emb in self.config.embeddings_urls.items()
|
235 |
+
})
|
236 |
+
features = datasets.Features(features)
|
237 |
|
238 |
return datasets.DatasetInfo(
|
239 |
# This is the description that will appear on the datasets page.
|
|
|
254 |
audio_path = {}
|
255 |
local_extracted_archive = {}
|
256 |
split_type = {"train": datasets.Split.TRAIN, "test": datasets.Split.TEST}
|
257 |
+
embeddings = {split: dict() for split in split_type}
|
258 |
|
259 |
for split in split_type:
|
260 |
+
if split in self.config.splits:
|
261 |
+
audio_path[split] = dl_manager.download(self.config.data_urls[split])
|
262 |
+
local_extracted_archive[split] = dl_manager.extract(
|
263 |
+
audio_path[split]) if not dl_manager.is_streaming else None
|
264 |
+
for emb_name, emb_data in self.config.embeddings_urls.items():
|
265 |
+
embeddings[split][emb_name] = np.load(dl_manager.download_and_extract(emb_data[split]) + "/arr_0.npy", allow_pickle=True).item()
|
266 |
|
267 |
return [
|
268 |
datasets.SplitGenerator(
|
|
|
271 |
"split": split,
|
272 |
"local_extracted_archive": local_extracted_archive[split],
|
273 |
"audio_files": dl_manager.iter_archive(audio_path[split]),
|
274 |
+
"embeddings": embeddings[split],
|
275 |
"metadata_file": dl_manager.download_and_extract(self.config.data_urls["metadata"]),
|
276 |
},
|
277 |
+
) for split in split_type if split in self.config.splits
|
278 |
]
|
279 |
|
280 |
def _generate_examples(
|
|
|
282 |
split: str,
|
283 |
local_extracted_archive: Union[Dict, List],
|
284 |
audio_files: Optional[Iterable],
|
285 |
+
embeddings: Optional[Dict],
|
286 |
metadata_file: Optional[str],
|
287 |
):
|
288 |
"""Yields examples."""
|
|
|
297 |
audio = {"path": path, "bytes": f.read()}
|
298 |
result = {field: None for field in data_fields}
|
299 |
result.update(metadata[metadata["path"] == lookup].T.squeeze().to_dict())
|
300 |
+
for emb_key in embeddings.keys():
|
301 |
+
result[emb_key] = embeddings[emb_key][lookup]
|
302 |
result["path"] = path
|
303 |
yield id_, {**result, "audio": audio}
|
304 |
id_ += 1
|