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

SegFormer B5 evaluation error on cityscapes #20

Closed
EvdoTheo opened this issue Feb 23, 2022 · 3 comments
Closed

SegFormer B5 evaluation error on cityscapes #20

EvdoTheo opened this issue Feb 23, 2022 · 3 comments

Comments

@EvdoTheo
Copy link

Hello, I try to implement an evaluation of segformer b5 to cityscapes dataset, but I keep getting an error related to the network's structure. I attached a file with the error.
error.txt
Even though I modified a custom.yaml file, which is like this one, I still keep getting an error. What can i do to solve this?

    MODEL:                                    
      NAME          : SegFormer                                           # name of the model you are using
      VARIANT       : B5                                                  # model variant
      PRETRAINED    : 'checkpoints/backbones/hardnet/hardnet_70.pth'              # backbone model's weight 
    
    DATASET:
      NAME          : cityscapes                                              # dataset name to be trained with (camvid, cityscapes, ade20k)
      ROOT          : '/media/evdo/DATA/diploma_project/cityscapes/gtFine_trainvaltest'                         # dataset root path
    
    TRAIN:
      IMAGE_SIZE    : [1024, 1024]    # training image size in (h, w)
      BATCH_SIZE    : 8               # batch size used to train
      EPOCHS        : 500             # number of epochs to train
      EVAL_INTERVAL : 50              # evaluation interval during training
      AMP           : false           # use AMP in training
      DDP           : false           # use DDP training
    
    LOSS:
      NAME          : ohemce          # loss function name (ohemce, ce, dice)
      CLS_WEIGHTS   : true            # use class weights in loss calculation
      THRESH        : 0.9             # ohemce threshold or dice delta if you choose ohemce loss or dice loss
    
    OPTIMIZER:
      NAME          : adamw           # optimizer name
      LR            : 0.01            # initial learning rate used in optimizer
      WEIGHT_DECAY  : 0.0001          # decay rate used in optimizer 
    
    SCHEDULER:
      NAME          : warmuppolylr    # scheduler name
      POWER         : 0.9             # scheduler power
      WARMUP        : 10              # warmup epochs used in scheduler
      WARMUP_RATIO  : 0.1             # warmup ratio
      
    
    EVAL:
      MODEL_PATH    : 'checkpoints/pretrained/segformer/segformer.b5.1024x1024.city.160k.pth'  # trained model file path
      IMAGE_SIZE    : [1024, 1024]                                                            # evaluation image size in (h, w)                       
      MSF:  
        ENABLE      : false                                                                 # multi-scale and flip evaluation  
        FLIP        : true                                                                  # use flip in evaluation  
        SCALES      : [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]                                     # scales used in MSF evaluation                
    
    
    TEST:
      MODEL_PATH    : 'checkpoints/pretrained/ddrnet/ddrnet_23_city.pth'                     # trained model file path
      FILE          : 'cityscapes/leftImg8bit_trainextra/leftImg8bit/train_extra/wurzburg' # filename or foldername 
      IMAGE_SIZE    : [480, 640]                                                           # inference image size in (h, w)
      OVERLAY       : false      
@sithu31296
Copy link
Owner

Change this line to model.load_state_dict(torch.load(str(model_path), map_location='cpu')['state_dict']).

@EvdoTheo
Copy link
Author

EvdoTheo commented Feb 23, 2022

Change this line to model.load_state_dict(torch.load(str(model_path), map_location='cpu')['state_dict']).

I changed it, but now I'm facing a new error

  File "/media/evdo/DATA/diploma_project/scripts/DDRNet/semantic-segmentation/semseg/val.py", line 85, in main
            model.load_state_dict(torch.load(str(model_path), map_location='cpu')['state_dict'])
  File "/home/evdo/.virtualenvs/testing/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1224, in load_state_dict
            self.__class__.__name__, "\n\t".join(error_msgs)))
  RuntimeError: Error(s) in loading state_dict for SegFormer:
                Unexpected key(s) in state_dict: "decode_head.conv_seg.weight", "decode_head.conv_seg.bias". 

@sithu31296
Copy link
Owner

Sorry for the late reply. Since you are using the model's weight from original SegFormer repo, it is not compatible with modified model implementation. But you can make it work if you modify the weights dict by eliminating some of the keys and values.

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

2 participants