multimodallearning / pytorch-mask-rcnn

Other
2.01k stars 557 forks source link

give user a chance to change the loaded state #12

Closed louis-she closed 11 months ago

louis-she commented 6 years ago

Sometimes we want to train a model with different classes number with COCO's, but still using COCO's pretrain weights. The strict=False option is not enough, we shoud manully modify the state_dict.

Usage:

def state_modifier(state_dict):
    state_dict.pop("mask.conv5.bias")
    state_dict.pop("mask.conv5.weight")
    state_dict.pop("classifier.linear_class.bias")
    state_dict.pop("classifier.linear_class.weight")
    state_dict.pop("classifier.linear_bbox.bias")
    state_dict.pop("classifier.linear_bbox.weight")
    return state_dict

model.load_weights(dsb_config.STATE_DICT_PATH, state_modifier)