SegFormer B5 evaluation error on cityscapes
EvdoTheo opened this issue · comments
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
Change this line to model.load_state_dict(torch.load(str(model_path), map_location='cpu')['state_dict'])
.
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".
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.