open-mmlab / mmsegmentation

OpenMMLab Semantic Segmentation Toolbox and Benchmark.
https://mmsegmentation.readthedocs.io/en/main/
Apache License 2.0
8.26k stars 2.62k forks source link

[KeyError: 'PALETTE'] while loading model after retraining #2039

Open laxmimerit opened 2 years ago

laxmimerit commented 2 years ago

Hi, I am getting following error while loading the model after retraining on my custom dataet.

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

KeyError: 'PALETTE'

I checked the keys in my saved model which are these

dict_keys(['epoch', 'iter', 'mmcv_version', 'time', 'CLASSES'])

Did training with following code

# Build the detector
model = build_segmentor(cfg.model)
# Add an attribute for visualization convenience
model.CLASSES = datasets[0].CLASSES
model.PALETTE = datasets[0].PALETTE

# Create work_dir
mmcv.mkdir_or_exist(osp.abspath(cfg.work_dir))
train_segmentor(model, datasets, cfg, distributed=False, validate=True, 
                meta=dict())
laxmimerit commented 2 years ago

UPDATE For time being I had to modify saved model with this code. It is just workaround. It worked!

model = torch.load('models/local/latest.pth')
model['meta']['PALETTE'] = color_palette
torch.save(model, 'models/local/latest_palette.pth')
MeowZheng commented 2 years ago

we will fix it asap

leizhenyu-lzy commented 1 year ago

Hi, I am getting following error while loading the model after retraining on my custom dataet.

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

KeyError: 'PALETTE'

I checked the keys in my saved model which are these

dict_keys(['epoch', 'iter', 'mmcv_version', 'time', 'CLASSES'])

Did training with following code

# Build the detector
model = build_segmentor(cfg.model)
# Add an attribute for visualization convenience
model.CLASSES = datasets[0].CLASSES
model.PALETTE = datasets[0].PALETTE

# Create work_dir
mmcv.mkdir_or_exist(osp.abspath(cfg.work_dir))
train_segmentor(model, datasets, cfg, distributed=False, validate=True, 
                meta=dict())

same problem

leizhenyu-lzy commented 1 year ago

we will fix it asap

When will it be solved?

laxmimerit commented 1 year ago

See workaround here https://github.com/open-mmlab/mmsegmentation/issues/2039#issuecomment-1239197221

On Sun, 16 Apr 2023 at 8:35 AM, LeiZhenYu @.***> wrote:

we will fix it asap

When will it be solved?

— Reply to this email directly, view it on GitHub https://github.com/open-mmlab/mmsegmentation/issues/2039#issuecomment-1510029152, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7QW5CMV4VU2T7IJ67WDCTXBNOXFANCNFSM6AAAAAAQGTOBQU . You are receiving this because you authored the thread.Message ID: @.***>