Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wgggSg opened this issue Jul 17, 2021 · 5 comments
Closed

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

wgggSg opened this issue Jul 17, 2021 · 5 comments

Comments

@wgggSg
Copy link

wgggSg commented Jul 17, 2021

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

@Junjun2016
Copy link
Collaborator

Hi @wgggSg
Maybe you have not saved the meta or PALETTE in the checkpoint.

@wgggSg
Copy link
Author

wgggSg commented Jul 17, 2021

@Junjun2016
It is indeed the problem you said. I have solved it by add the code

cfg.checkpoint_config.meta = dict(
    CLASSES=classes,
    PALETTE=palette)

to my config file, thanks!

@wgggSg wgggSg closed this as completed Jul 17, 2021
@459737087
Copy link

Good job!

@LansonChen
Copy link

@Junjun2016 It is indeed the problem you said. I have solved it by add the code

cfg.checkpoint_config.meta = dict(
    CLASSES=classes,
    PALETTE=palette)

to my config file, thanks!
@wgggSg
hi,did you use jupyter notebook to modify those configs? Could u share one copy of the ipynb to me, thanks!

@wgggSg
Copy link
Author

wgggSg commented Jun 15, 2022

@Junjun2016 It is indeed the problem you said. I have solved it by add the code

cfg.checkpoint_config.meta = dict(
    CLASSES=classes,
    PALETTE=palette)

to my config file, thanks!
@wgggSg
hi,did you use jupyter notebook to modify those configs? Could u share one copy of the ipynb to me, thanks!

sorry, it have been a long time I didn't use mmsegmentation, so that my code file couldn't be found.....
I remembered i add the code above to train.py so that the error is solved, maybe just add PALETTE and CLASSES to your checkpoint could also solve this problem.

aravind-h-v pushed a commit to aravind-h-v/mmsegmentation that referenced this issue Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants