Skip to content

Commit

Permalink
add accuracy checker config for aclnet
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova committed Nov 10, 2020
1 parent 78a2471 commit a517667
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 1 deletion.
23 changes: 23 additions & 0 deletions models/public/aclnet/accuracy-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
models:
- name: aclnet

launchers:
- framework: dlsdk
adapter: classification

datasets:
- name: sound_classification

preprocessing:
- type: clip_audio
duration: 1
overlap: 50%
- type: audio_normalization

metrics:
- type: accuracy
name: top@1
top_k: 1
- type: accuracy
name: top@5
top_k: 5
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ The main difference between this converter and `super_resolution` in data organi
* `annotation_file` - path to json file containing annotations to the dataset ({index: {path:"...", labels:[...], bbox:[...] (optional), ...})
* `label_id` - number of label in the annotation file representing spoof/real labels
* `dataset_meta_file` - path to json file with dataset meta (e.g. label_map)
* `sound_classification` - converts dataset for sound classification to `ClassificationAnnotation`. The dataset should be represented by directory with input wav files and annotation in 2 column csv format, where first column is audio file name and second is label id from dataset.
* `annotation_file` - csv file with selected subset for evaluation, file structure described above.
* `audio_dir` - directory with input data, (optional, required only if you want check file existence during annotation conversion).

## <a name="customizing-dataset-meta"></a>Customizing Dataset Meta
There are situations when we need customize some default dataset parameters (e.g. replace original dataset label map with own.)
You are able to overload parameters such as `label_map`, `segmentation_colors`, `background_label` using `dataset_meta_file` argument.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
from .mpii import MPIIDatasetConverter
from .mapillary_20 import Mapillary20Converter
from .antispoofing import AntispoofingDatasetConverter
from .sound_classification_converter import SoundClassificationFormatConverter

__all__ = [
'BaseFormatConverter',
Expand Down Expand Up @@ -168,5 +169,6 @@
'PlaceRecognitionDatasetConverter',
'ClutteredMNISTConverter',
'MPIIDatasetConverter',
'AntispoofingDatasetConverter'
'AntispoofingDatasetConverter',
'SoundClassificationFormatConverter',
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Copyright (c) 2018-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from .format_converter import ConverterReturn, BaseFormatConverter
from ..config import PathField
from ..representation import ClassificationAnnotation
from ..utils import read_csv, get_path, check_file_existence


class SoundClassificationFormatConverter(BaseFormatConverter):
__provider__ = 'sound_classification'

@classmethod
def parameters(cls):
parameters = super().parameters()
parameters.update({
'annotation_file': PathField(description="Path to annotation in cvs format."),
'audio_dir': PathField(
is_directory=True, optional=True,
description='Path to dataset audio files, used only for content existence check'
)
})

return parameters

def configure(self):
self.annotation_file = self.get_value_from_config('annotation_file')
self.audio_dir = self.get_value_from_config('audio_dir') or self.annotation_file.parent

def convert(self, check_content=False, progress_callback=None, progress_interval=100, **kwargs):
annotation = []
content_errors = [] if check_content else None
original_annotation = read_csv(get_path(self.annotation_file), fieldnames=['identifier', 'label'])
num_iterations = len(original_annotation)
for audio_id, audio in enumerate(original_annotation):
identifier = audio['identifier']
label = int(audio['label'])
if check_content:
if not check_file_existence(self.audio_dir / identifier):
content_errors.append('{}: does not exist'.format(self.audio_dir / identifier))

annotation.append(ClassificationAnnotation(identifier, label))
if progress_callback is not None and audio_id % progress_interval == 0:
progress_callback(audio_id / num_iterations * 100)

return ConverterReturn(annotation, None, content_errors)
1 change: 1 addition & 0 deletions tools/accuracy_checker/configs/aclnet.yml
9 changes: 9 additions & 0 deletions tools/accuracy_checker/dataset_definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1055,3 +1055,12 @@ datasets:
label_id: 43
annotation: antispoofing.pickle
dataset_meta: antispoofing.json

- name: sound_classification
data_source: audio_dataset
annotation_conversion:
converter: sound_classification
annotation_file: audio_dataset/validation.csv
audio_dir: audio_dataset/data
annotation: sound_classification.pickle
reader: wav_reader

0 comments on commit a517667

Please sign in to comment.