Closed jakeum closed 3 years ago
ReadonlyConfigError: Cannot change read-only config container full_key: num_classes reference_type=Optional[Dict[Union[str, Enum], Any]] object_type=dict
import effdet from effdet import get_efficientdet_config, EfficientDet, DetBenchTrain from effdet.efficientdet import HeadNet
weight_path = '/media/ssd1/jake/eff_weights/tf_efficientdet_d5-ef44aea8.pth'
def get_net(): config = get_efficientdet_config('tf_efficientdet_d5') net = EfficientDet(config, pretrained_backbone=False) checkpoint = torch.load(weight_path) #d3-d7 ('efficientdet_model' folder) net.load_state_dict(checkpoint) print(config) config.num_classes = 1 config.image_size = 512 net.class_net = HeadNet(config, num_outputs=config.num_classes, norm_kwargs=dict(eps=.001, momentum=.01)) return DetBenchTrain(net, config) net = get_net()
--------------------------------------------------------------------------- ReadonlyConfigError Traceback (most recent call last) <ipython-input-67-efc87f4a5fe3> in <module> 15 net.class_net = HeadNet(config, num_outputs=config.num_classes, norm_kwargs=dict(eps=.001, momentum=.01)) 16 return DetBenchTrain(net, config) ---> 17 net = get_net() <ipython-input-67-efc87f4a5fe3> in get_net() 11 net.load_state_dict(checkpoint) 12 print(config) ---> 13 config.num_classes = 1 14 config.image_size = 512 15 net.class_net = HeadNet(config, num_outputs=config.num_classes, norm_kwargs=dict(eps=.001, momentum=.01)) ~/venv_11.1/lib/python3.6/site-packages/omegaconf/dictconfig.py in __setattr__(self, key, value) 276 if isinstance(e, OmegaConfBaseException) and e._initialized: 277 raise e --> 278 self._format_and_raise(key=key, value=value, cause=e) 279 assert False 280 ~/venv_11.1/lib/python3.6/site-packages/omegaconf/base.py in _format_and_raise(self, key, value, cause, type_override) 99 msg=str(cause), 100 cause=cause, --> 101 type_override=type_override, 102 ) 103 assert False ~/venv_11.1/lib/python3.6/site-packages/omegaconf/_utils.py in format_and_raise(node, key, value, msg, cause, type_override) 692 ex.ref_type_str = ref_type_str 693 --> 694 _raise(ex, cause) 695 696 ~/venv_11.1/lib/python3.6/site-packages/omegaconf/_utils.py in _raise(ex, cause) 608 else: 609 ex.__cause__ = None --> 610 raise ex # set end OC_CAUSE=1 for full backtrace 611 612 ReadonlyConfigError: Cannot change read-only config container full_key: num_classes reference_type=Optional[Dict[Union[str, Enum], Any]] object_type=dict
By design, use the functionally provided so config is changed properly
Facing the same issue again. Not able to update the num_classes in config. Throwing same exception as above
ReadonlyConfigError: Cannot change read-only config container full_key: num_classes reference_type=Optional[Dict[Union[str, Enum], Any]] object_type=dict
import effdet from effdet import get_efficientdet_config, EfficientDet, DetBenchTrain from effdet.efficientdet import HeadNet
weight_path = '/media/ssd1/jake/eff_weights/tf_efficientdet_d5-ef44aea8.pth'
def get_net(): config = get_efficientdet_config('tf_efficientdet_d5') net = EfficientDet(config, pretrained_backbone=False) checkpoint = torch.load(weight_path) #d3-d7 ('efficientdet_model' folder) net.load_state_dict(checkpoint) print(config) config.num_classes = 1 config.image_size = 512 net.class_net = HeadNet(config, num_outputs=config.num_classes, norm_kwargs=dict(eps=.001, momentum=.01)) return DetBenchTrain(net, config) net = get_net()