def build(self): """Build this configuration. Set any values into the TF object detection pipeline config as necessary. """ self.validate() b = deepcopy(self) # Check if a pretrained model was assigned. pretrained_model = b.config.get('pretrained_model_uri') if pretrained_model: b = b.with_config({'fineTuneCheckpoint': pretrained_model}) else: b = b.with_config( { 'fineTuneCheckpoint': '' }, ignore_missing_keys=True) for config_mod, ignore_missing_keys, set_missing_keys in b.config_mods: try: set_nested_keys(b.config['tfod_config'], config_mod, ignore_missing_keys, set_missing_keys) except Exception as e: raise rv.ConfigError( 'Error setting configuration {}'.format(config_mod)) from e return TFObjectDetectionConfig(**b.config)
def test_set_nested_keys_sets_missing_keys_in_dict(self): d = { 'one': 1, 'two': 2, 'three': { 'four': 4, 'five': 5, 'six': [ { 'seven': 7 }, { 'eight': 8 }, { 'nine': 9 }, ], 'ten': { 'eleven': 11 } } } expected = { 'one': 1, 'two': 2, 'three': { 'four': 4, 'five': 5, 'six': [ { 'seven': 7 }, { 'eight': 8 }, { 'nine': 9 }, ], 'ten': { 'eleven': 11 }, 'twelve': 12 } } mod = {'three': {'twelve': 12}} set_nested_keys(d, mod, set_missing_keys=True) self.assertEqual(d, expected)
def test_set_nested_keys_finds_nested(self): d = { 'one': 1, 'two': 2, 'three': { 'four': 4, 'five': 5, 'six': [ { 'seven': 7 }, { 'eight': 8 }, { 'nine': 9 }, ], 'ten': { 'eleven': 11 } } } expected = { 'one': 1, 'two': 2, 'three': { 'four': 4, 'five': 55, 'six': [ { 'seven': 7 }, { 'eight': 8 }, { 'nine': 9 }, ], 'ten': { 'eleven': 11 } } } set_nested_keys(d, {'five': 55}) self.assertEqual(d, expected)
def test_set_nested_keys_ignores_missing_keys(self): d = { 'one': 1, 'two': 2, 'three': { 'four': 4, 'five': 5, 'six': [ { 'seven': 7 }, { 'eight': 8 }, { 'nine': 9 }, ], 'ten': { 'eleven': 11 } } } expected = { 'one': 1, 'two': 2, 'three': { 'four': 4, 'five': 5, 'six': [ { 'seven': 7 }, { 'eight': 8 }, { 'nine': 9 }, ], 'ten': { 'eleven': 11 } } } set_nested_keys(d, {'twenty': 20}, ignore_missing_keys=True) self.assertEqual(d, expected)
def build(self): """Build this configuration. """ self.validate() b = deepcopy(self) for config_mod, ignore_missing_keys, set_missing_keys in b.config_mods: try: set_nested_keys(b.config['tfdl_config'], config_mod, ignore_missing_keys, set_missing_keys) except Exception as e: raise rv.ConfigError( 'Error setting configuration {}'.format(config_mod)) from e return TFDeeplabConfig(**b.config)
def build(self): """Build this configuration, setting any values into the TF object detection pipeline config as necessary. """ self.validate() b = deepcopy(self) for config_mod, ignore_missing_keys, set_missing_keys in b.config_mods: try: set_nested_keys(b.config['kc_config'], config_mod, ignore_missing_keys, set_missing_keys) except Exception as e: raise rv.ConfigError( 'Error setting configuration {}'.format(config_mod)) from e return KerasClassificationConfig(**b.config)