コード例 #1
0
    def __init__(self):
        super(WholeNetwork, self).__init__()
        self.vgg16_extractor = VGG16Extractor()
        self.lm_branch = const.LM_BRANCH(const.LM_SELECT_VGG_CHANNEL)
        self.downsample = nn.Upsample((28, 28),
                                      mode='bilinear',
                                      align_corners=False)
        self.attention_pred_net = CustomUnetGenerator(512 + 1,
                                                      512,
                                                      num_downs=2,
                                                      ngf=32,
                                                      last_act='tanh')
        self.pooled_4 = nn.MaxPool2d(kernel_size=2, stride=2)
        self.conv5_1 = nn.Conv2d(512, 512, 3, padding=1)
        self.conv5_2 = nn.Conv2d(512, 512, 3, padding=1)
        self.conv5_3 = nn.Conv2d(512, 512, 3, padding=1)
        conv5_para_vgg16 = [
            self.vgg16_extractor.vgg[-7].state_dict(),
            self.vgg16_extractor.vgg[-5].state_dict(),
            self.vgg16_extractor.vgg[-3].state_dict(),
        ]
        self.conv5_1.load_state_dict(conv5_para_vgg16[0])
        self.conv5_2.load_state_dict(conv5_para_vgg16[1])
        self.conv5_3.load_state_dict(conv5_para_vgg16[2])
        self.pooled_5 = nn.MaxPool2d(kernel_size=2, stride=2)

        self.category_fc1 = nn.Linear(512 * 7 * 7, 1024)
        self.category_fc2 = nn.Linear(1024, 48)
        self.attr_fc1 = nn.Linear(512 * 7 * 7, 1024)
        self.attr_fc2 = nn.Linear(1024, 1000 * 2)

        self.category_loss_func = torch.nn.CrossEntropyLoss()
        self.attr_loss_func = torch.nn.CrossEntropyLoss(weight=torch.tensor(
            [const.WEIGHT_ATTR_NEG, const.WEIGHT_ATTR_POS]).to(const.device))
コード例 #2
0
 def __init__(self, use_iorn=False):
     super(LandmarkExpNetwork, self).__init__()
     self.vgg16_extractor = VGG16Extractor(use_iorn=use_iorn)
     self.lm_branch = const.LM_BRANCH(const.LM_SELECT_VGG_CHANNEL)