## VGGEncoder4 vgg4 = load_lua('pretrained/encoder.t7', long_size=8) e4 = VGGEncoder() weight_assign(vgg4, e4, { 'conv0': 0, 'conv1_1': 2, 'conv1_2': 5, 'conv2_1': 9, 'conv2_2': 12, 'conv3_1': 16, 'conv3_2': 19, 'conv3_3': 22, 'conv3_4': 25, 'conv4_1': 29, }) torch.save(e4.state_dict(), 'pretrained/encoder_pretrained.pth') ## VGGDecoder4 inv4 = load_lua('pretrained/recon.t7', long_size=8) d4 = VGGDecoder(num_class=3,use_softmax=False) weight_assign(inv4, d4, { 'conv4_1': 1, 'conv3_4': 5, 'conv3_3': 8, 'conv3_2': 11, 'conv3_1': 14, 'conv2_2': 18, 'conv2_1': 21, 'conv1_2': 25, 'conv1_1': 28, })
p_wct.e4.load_state_dict(torch.load('pth_models/vgg_normalised_conv4.pth')) p_wct.d4.load_state_dict(torch.load('pth_models/feature_invertor_conv4.pth')) if __name__ == '__main__': if not os.path.exists('pth_models'): os.mkdir('pth_models') ## VGGEncoder1 vgg1 = load_lua('models/vgg_normalised_conv1_1_mask.t7') e1 = VGGEncoder(1) weight_assign(vgg1, e1, { 'conv0': 0, 'conv1_1': 2, }) torch.save(e1.state_dict(), 'pth_models/vgg_normalised_conv1.pth') ## VGGDecoder1 inv1 = load_lua('models/feature_invertor_conv1_1_mask.t7') d1 = VGGDecoder(1) weight_assign(inv1, d1, { 'conv1_1': 1, }) torch.save(d1.state_dict(), 'pth_models/feature_invertor_conv1.pth') ## VGGEncoder2 vgg2 = load_lua('models/vgg_normalised_conv2_1_mask.t7') e2 = VGGEncoder(2) weight_assign(vgg2, e2, { 'conv0': 0, 'conv1_1': 2,
p_wct.d4.load_state_dict( torch.load('pth_models/feature_invertor_conv4.pth')) if __name__ == '__main__': if not os.path.exists('pth_models'): os.mkdir('pth_models') ## VGGEncoder1 vgg1 = load_lua('models/vgg_normalised_conv1_1_mask.t7') e1 = VGGEncoder(1) weight_assign(vgg1, e1, { 'conv0': 0, 'conv1_1': 2, }) torch.save(e1.state_dict(), 'pth_models/vgg_normalised_conv1.pth') ## VGGDecoder1 inv1 = load_lua('models/feature_invertor_conv1_1_mask.t7') d1 = VGGDecoder(1) weight_assign(inv1, d1, { 'conv1_1': 1, }) torch.save(d1.state_dict(), 'pth_models/feature_invertor_conv1.pth') ## VGGEncoder2 vgg2 = load_lua('models/vgg_normalised_conv2_1_mask.t7') e2 = VGGEncoder(2) weight_assign(vgg2, e2, { 'conv0': 0, 'conv1_1': 2,