wasidennis / AdaptSegNet

Learning to Adapt Structured Output Space for Semantic Segmentation, CVPR 2018 (spotlight)
850 stars 203 forks source link

Error when training using VGG-16 model #45

Closed alphjheon closed 5 years ago

alphjheon commented 5 years ago

@wasidennis @m3phisto @hfslyc , i am trying to run the code (VGG source only). But when i run as you mentioned in previous thread, with --lambda-adv-target1 0 --lambda-adv-target2 i got this error: "train_gta2cityscapes_multi.py", line 311, in main pred1, pred2 = model(images) ValueError: not enough values to unpack (expected 2, got 1)`

Are there any modifications that have to be done for training source only (without) adaptation experiment? If yes, i would be pleased if you could share the code.

wasidennis commented 5 years ago

In order to train the VGG model from ImageNet pre-trained weights, please download the weights here: https://www.dropbox.com/s/r8dx8xuqpsr3do3/vgg16-00b39a1b-updated.pth?dl=0.

In the training code, you should also load the pre-trained weights as the follow: "model = DeeplabVGG(num_classes=args.num_classes, vgg16_caffe_path=args.restore_from, pretrained=True)”

alphjheon commented 5 years ago

@wasidennis this is not the case. An error occurs: RuntimeError: Error(s) in loading state_dict for DeeplabVGG: Unexpected key(s) in state_dict: "0.weight", "0.bias", "2.weight", "2.bias", "5.weight", "5.bias", "7.weight", "7.bias", "10.weight", "10.bias", "12.weight", "12.bias", "14.weight", "14.bias", "17.weight", "17.bias", "19.weight", "19.bias", "21.weight", "21.bias", "24.weight", "24.bias", "26.weight", "26.bias", "28.weight", "28.bias", "6.weight", "6.bias", "3.weight", "3.bias"

Suspecting that lines 190-198 are responsible for this, and commenting them: `

 # Create network
    if args.model == 'DeeplabVGG':
        model = DeeplabVGG(num_classes=args.num_classes, vgg16_caffe_path=args.restore_from, pretrained=True)
        if args.restore_from[:4] == 'http' :
            saved_state_dict = model_zoo.load_url(args.restore_from)
        else:
            saved_state_dict = torch.load(args.restore_from)

        new_params = model.state_dict().copy()
        """
        for i in saved_state_dict:
            # Scale.layer5.conv2d_list.3.weight
            i_parts = i.split('.')
            # print i_parts
            if not args.num_classes == 19 or not i_parts[1] == 'layer5':
                new_params['.'.join(i_parts[1:])] = saved_state_dict[i]
                # print i_parts
        """
        model.load_state_dict(new_params)

` A new error occurs:

File "train_gta2cityscapes_multi.py", line 312, in main pred1, pred2 = model(images) ValueError: not enough values to unpack (expected 2, got 1).

In your code, lines 190-193. I have lost one day and still can't find out the way to run the experiment.

wasidennis commented 5 years ago

After you define the VGG model and load the weights, you can removes the lines below "if args.restore_from[:4] == 'http' :".

For the new error, this is because we only use the single-level version for the VGG model. You can remove all the lines relevant to "D1" and "loss_adv_target1" and use "pred2 = model(images)".

alphjheon commented 5 years ago

Thank you @wasidennis ! Regarding the training parameters (learning rate, weight decay) are they same as the experiment with the ResNet-101 ?

wasidennis commented 5 years ago

Yes, we use the same ones as the ResNet.