def test_annotation_conversion_converter_without_required_options_raise_config_error( self): addition_options = {'annotation_conversion': {'converter': 'wider'}} config = copy_dataset_config(self.dataset_config) config.update(addition_options) with pytest.raises(ConfigError): Dataset(config)
def test_annotation_conversion_raise_config_error_on_extra_args(self): addition_options = { 'annotation_conversion': { 'converter': 'wider', 'annotation_file': 'file', 'something_extra': 'extra' } } config = copy_dataset_config(self.dataset_config) config.update(addition_options) with pytest.raises(ConfigError): Dataset(config)
def test_successful_annotation_conversion(self, mocker): addition_options = { 'annotation_conversion': { 'converter': 'wider', 'annotation_file': Path('file') } } config = copy_dataset_config(self.dataset_config) config.update(addition_options) annotation_converter_mock = mocker.patch( 'openvino.tools.accuracy_checker.annotation_converters.WiderFormatConverter.convert', return_value=ConverterReturn( make_representation("0 0 0 5 5", True), None, None)) Dataset(config) annotation_converter_mock.assert_called_once_with()
def test_annotation_conversion_with_negative_subset_size(self, mocker): addition_options = { 'annotation_conversion': { 'converter': 'wider', 'annotation_file': Path('file') }, 'subsample_size': -1 } config = copy_dataset_config(self.dataset_config) config.update(addition_options) converted_annotation = make_representation( ['0 0 0 5 5', '0 1 1 10 10'], True) mocker.patch( 'openvino.tools.accuracy_checker.annotation_converters.WiderFormatConverter.convert', return_value=ConverterReturn(converted_annotation, None, None)) with pytest.raises(ConfigError): Dataset(config)
def test_annotation_conversion_not_convert_twice(self, mocker): addition_options = { 'annotation_conversion': { 'converter': 'wider', 'annotation_file': Path('file') }, 'annotation': Path('custom') } config = copy_dataset_config(self.dataset_config) config.update(addition_options) converted_annotation = make_representation('0 0 0 5 5', True) annotation_reader_mock = mocker.patch( 'openvino.tools.accuracy_checker.dataset.read_annotation', return_value=converted_annotation) Dataset(config) annotation_reader_mock.assert_called_once_with(Path('custom'), True)
def test_annotation_conversion_subset_size(self, mocker): addition_options = { 'annotation_conversion': { 'converter': 'wider', 'annotation_file': Path('file') }, 'subsample_size': 1 } config = copy_dataset_config(self.dataset_config) config.update(addition_options) converted_annotation = make_representation( ['0 0 0 5 5', '0 1 1 10 10'], True) mocker.patch( 'openvino.tools.accuracy_checker.annotation_converters.WiderFormatConverter.convert', return_value=ConverterReturn(converted_annotation, None, None)) dataset = Dataset(config) assert dataset.data_provider.annotation_provider._data_buffer == { converted_annotation[1].identifier: converted_annotation[1] }
def test_annotation_conversion_save_subset(self, mocker): addition_options = { 'annotation_conversion': { 'converter': 'wider', 'annotation_file': Path('file') }, 'annotation': Path('custom'), 'subsample_size': 1, } config = copy_dataset_config(self.dataset_config) config.update(addition_options) converted_annotation = make_representation( ['0 0 0 5 5', '0 1 1 10 10'], True) mocker.patch( 'openvino.tools.accuracy_checker.annotation_converters.WiderFormatConverter.convert', return_value=ConverterReturn(converted_annotation, None, None)) annotation_saver_mock = mocker.patch( 'openvino.tools.accuracy_checker.dataset.save_annotation') mocker.patch('pathlib.Path.exists', return_value=False) Dataset(config) annotation_saver_mock.assert_called_once_with( [converted_annotation[1]], None, Path('custom'), None, config)
def test_create_data_provider_with_subset_file(self, mocker): mocker.patch('pathlib.Path.exists', return_value=True) mocker.patch('openvino.tools.accuracy_checker.dataset.read_yaml', return_value=['1']) addition_options = { 'annotation_conversion': { 'converter': 'wider', 'annotation_file': Path('file') }, "subset_file": "subset.yml" } config = copy_dataset_config(self.dataset_config) config.update(addition_options) converted_annotation = make_representation( ['0 0 0 5 5', '0 1 1 10 10'], True) mocker.patch( 'openvino.tools.accuracy_checker.annotation_converters.WiderFormatConverter.convert', return_value=ConverterReturn(converted_annotation, None, None)) dataset = Dataset(config) assert len(dataset.data_provider) == 1 assert dataset.identifiers == ['1'] assert dataset.data_provider.full_size == 2
def test_annotation_conversion_unknown_converter_raise_config_error(self): addition_options = {'annotation_conversion': {'converter': 'unknown'}} config = copy_dataset_config(self.dataset_config) config.update(addition_options) with pytest.raises(ValueError): Dataset(config)
def test_setting_custom_dataset_with_missed_annotation_raises_config_error_exception( self): local_dataset = copy_dataset_config(self.dataset_config) local_dataset.pop('annotation') with pytest.raises(ConfigError): Dataset(local_dataset)
def test_missed_name_raises_config_error_exception(self): local_dataset = copy_dataset_config(self.dataset_config) local_dataset.pop('name') with pytest.raises(ConfigError): Dataset(local_dataset)