Skip to content

KeyError: 'PALETTE' when use method init_segmentor() #710

Closed
@amadeusneko

Description

@amadeusneko

The error code:

Use load_from_local loader
~/workspace/mmcv-test/mmseg/models/backbones/hrnet.py:298: UserWarning: DeprecationWarning: pretrained is a deprecated, please use "init_cfg" instead
  warnings.warn('DeprecationWarning: pretrained is a deprecated, '
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-9-da74faa07110> in <module>
      7     pth_file = osp.join(work_dir, 'iter_30000.pth')
      8     print(torch.load(pth_file))
----> 9     model = init_segmentor(cfg, pth_file, device='cuda:0')
     10 else:
     11     model.cfg = cfg

~/workspace/mmcv-test/mmseg/apis/inference.py in init_segmentor(config, checkpoint, device)
     33         checkpoint = load_checkpoint(model, checkpoint, map_location='cpu')
     34         model.CLASSES = checkpoint['meta']['CLASSES']
---> 35         model.PALETTE = checkpoint['meta']['PALETTE']
     36     model.cfg = config  # save the config in the model for convenience
     37     model.to(device)

KeyError: 'PALETTE'

My CustomDataset:

@DATASETS.register_module()
class BDD100KLaneLabelDataset(CustomDataset):
  CLASSES = classes
  PALETTE = palette
  def __init__(self, split, **kwargs):
    super().__init__(img_suffix='.jpg', seg_map_suffix='.png', 
                     split=split, **kwargs)
    assert osp.exists(self.img_dir) and self.split is not None
print('done')

I solved it using a simple way:
modify model.PALETTE = checkpoint['meta']['PALETTE'] to model.PALETTE = my_paletee
at line 35 in mmseg/apis/inference.py.

But I want to know an official way to solve this error, please tell me.
thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions