def set_defaults(self, cmd, args): """Set up environment defaults before executing the command. """ if self.model_plugin: self.model_plugin.set_defaults(cmd, args, self) self._config['device'] = parse_device(self._config.get('device', {})) self._config['data'] = parse_data(self._config.get('data', {}))
def _load_yaml_and_configure(self, path, label, cache, device, device_memory): # pylint: disable=R0913 doc = load_yaml_file(path, label) try: doc['device'] = parse_device(doc.get('device', {}), device_id=device, device_memory=device_memory) doc['data'] = parse_data(doc.get('data', {}), cache=cache, plugins=self.plugins) if 'random-seed' in doc and not isinstance(doc['random-seed'], int): raise VergeMLError('Invalid value option random-seed.', 'random-seed must be an integer value.', hint_type='value', hint_key='random-seed') except VergeMLError as err: if err.hint_key: with open(path) as file: definition = yaml_find_definition(file, err.hint_key, err.hint_type) if definition: line, column, length = definition err.message = display_err_in_file(path, line, column, str(err), length) # clear suggestion because it is already contained in the error message. err.suggestion = None raise err else: raise err else: raise err return doc
def test_input_shortcut_2(): plugins = _DictPluginManager() plugins.set('vergeml.io', 'image', ImageSource) assert parse_data({'input': 'image'}) == { 'input': { 'type': 'image', 'input-patterns': ['**/*.jpg', '**/*.jpeg', '**/*.png', '**/*.bmp'] }, 'cache': 'auto', 'preprocess': [] }
def test_validate_preprocess(): plugins = _DictPluginManager() plugins.set('vergeml.operation', 'augment', AugmentOperation) assert parse_data({'preprocess': [{ 'op': 'augment', 'variants': 4 }]}) == { 'cache': 'auto', 'preprocess': [{ 'op': 'augment', 'variants': 4 }] }
def test_apply_config_image(): plugins = _DictPluginManager() plugins.set('vergeml.io', 'image', ImageSource) assert parse_data({'input': { 'type': 'image', 'input-patterns': '*.jpg' }}) == { 'input': { 'type': 'image', 'input-patterns': ['*.jpg'] }, 'cache': 'auto', 'preprocess': [] }
def test_apply_config_image_invalid(): plugins = _DictPluginManager() plugins.set('vergeml.io', 'image', ImageSource) with pytest.raises(VergeMLError): parse_data({'input': {'type': 'image', 'input-patternz': '*.jpg'}})
def test_validate_preprocess_invalid(): plugins = _DictPluginManager() plugins.set('vergeml.operation', 'augment', AugmentOperation) with pytest.raises(VergeMLError, match=r".*Did you mean 'variants'.*"): assert parse_data({'preprocess': [{'op': 'augment', 'variantz': 4}]})