zijundeng / pytorch-semantic-segmentation

PyTorch for Semantic Segmentation
MIT License
1.73k stars 393 forks source link

About caffe-VGG16 #26

Open jiujing23333 opened 6 years ago

jiujing23333 commented 6 years ago

I followed the Readme and download pretrained model from this url: https://github.com/jcjohnson/pytorch-vgg, but a problem was reported because of unligned index of weight. I modified the code as follow: ` if pretrained: if caffe:

load the pretrained vgg16 used by the paper's author

            dict = torch.load(vgg16_caffe_path)
            dict['classifier.0.weight'] = dict['classifier.1.weight']
            dict['classifier.0.bias'] = dict['classifier.1.bias']
            dict['classifier.3.weight'] = dict['classifier.4.weight']
            dict['classifier.3.bias'] = dict['classifier.4.bias']
            del dict['classifier.1.weight']
            del dict['classifier.1.bias']
            del dict['classifier.4.weight']
            del dict['classifier.4.bias']
            vgg.load_state_dict(dict)`

Then it could run, but training loss didn't decrease. What's wrong with this process?

jiujing23333 commented 6 years ago

Sorry, I failed to copy the code clearly.

dict = torch.load(vgg16_caffe_path) dict['classifier.0.weight'] = dict['classifier.1.weight'] dict['classifier.0.bias'] = dict['classifier.1.bias'] dict['classifier.3.weight'] = dict['classifier.4.weight'] dict['classifier.3.bias'] = dict['classifier.4.bias'] del dict['classifier.1.weight'] del dict['classifier.1.bias'] del dict['classifier.4.weight'] del dict['classifier.4.bias'] vgg.load_state_dict(dict)

zijundeng commented 6 years ago

Actually, I did not use the pretrained model provided by jcjohnson. Instead, I use his code to convert the caffe vgg model. I am not sure whether it matters.