nii-yamagishilab / Capsule-Forensics-v2

Implementation of the Capsule-Forensics-v2
BSD 3-Clause "New" or "Revised" License
119 stars 24 forks source link

Does not save weight after training VGG-19 #23

Closed TRANDONGXYZ closed 1 year ago

TRANDONGXYZ commented 1 year ago

Why is the weight of VGG-19 not saved after training VGG-19 Does that affect the testing process?

You have initialized vgg_ext and capnet, but you only save capnet.

vgg_ext = model_big.VggExtractor()
capnet = model_big.CapsuleNet(2, opt.gpu_id)
# do checkpointing & validation
torch.save(capnet.state_dict(), os.path.join(opt.outf, 'capsule_%d.pt' % epoch))
torch.save(optimizer.state_dict(), os.path.join(opt.outf, 'optim_%d.pt' % epoch))

It doesn't really freeze the first 9 layers because when we check with the command:

def freeze_gradient(self, begin=0, end=9):
    for i in range(begin, end+1):
        self.vgg_1[i].requires_grad = False
for param in vgg_ext.parameters():
    print(param.requires_grad)

then all are equal to True.

Thank you.

honghuy127 commented 1 year ago

Hi, the optimizer only optimizes the capnet, so the vgg's weights will not change. optimizer = Adam(capnet.parameters(), lr=opt.lr, betas=(opt.beta1, 0.999))

Regarding the freezing weights code, it was used for another experiment that I tried to finetune a part of the VGG (not included in this repository).