示例#1
0
    def set_input(self, input):
        """
        the structure of the input.
        {
        'image':Bx3x96x96 FloatTensor
        'pose':Bx1 FloatTensor
        'identity':Bx1 FloatTensor
        }

        test_pose (B): used for the test='initial learning rate
        """
        self.load_input(input)
        self.image = torch.squeeze(torch.stack(self.image, dim=0))
        self.batchsize = len(self.pose)
        self.pose = torch.LongTensor(self.pose)
        self.frontal_pose = torch.LongTensor(
            np.random.randint(self.N_p, size=self.batchsize))

        # if self.is_Train:
        self.input_pose = one_hot(self.frontal_pose, self.N_p)
        # else:
        #     self.input_pose = one_hot(test_pose.long(), self.N_p)

        self.identity = torch.LongTensor(self.identity)
        self.fake_identity = torch.zeros(
            self.batchsize).long()  # 0 indicates fake
        self.noise = torch.FloatTensor(
            np.random.normal(loc=0.0,
                             scale=0.3,
                             size=(self.batchsize, self.N_z)))

        #cuda
        if self.opt.gpu_ids:
            self.image = self.image.cuda()
            self.pose = self.pose.cuda()
            self.frontal_pose = self.frontal_pose.cuda()
            self.input_pose = self.input_pose.cuda()
            self.identity = self.identity.cuda()
            self.fake_identity = self.fake_identity.cuda()
            self.noise = self.noise.cuda()

        self.image = Variable(self.image)
        self.pose = Variable(self.pose)
        self.frontal_pose = Variable(self.frontal_pose)
        self.input_pose = Variable(self.input_pose)
        self.identity = Variable(self.identity)
        self.fake_identity = Variable(self.fake_identity)
        self.noise = Variable(self.noise)
示例#2
0
    def set_input(self, input):
        """
        the structure of the input.
        {
        'image':Bx3x96x96 FloatTensor
        'pose':Bx1 FloatTensor
        'identity':Bx1 FloatTensor
        }

        test_pose (B): used for the test='initial learning rate
        """
        self.load_input(input)
        self.batchsize = []
        self.rand_pose = []
        self.frontal_pose = []
        self.input_pose = []
        self.fake_identity = []
        self.noise = []
        self.frontal_image = [[] for r in range(len(self.pose))]
        self.profile_image = [[] for r in range(len(self.pose))]
        # self.real_frontal_pose = [[] for r in range(len(self.pose))]
        # self.real_profile_pose = [[] for r in range(len(self.pose))]
        # self.frontal_id = [[] for r in range(len(self.pose))]
        self.profile_id = [[] for r in range(len(self.pose))]
        self.frontal_name = [[] for r in range(len(self.pose))]
        self.profile_name = [[] for r in range(len(self.pose))]
        for j in range(len(self.pose)):
            for e in range(len(self.pose[j])):
                if self.pose[j][e]:
                    self.frontal_image[j].append(self.image[j][e])
                    # self.real_frontal_pose[j].append(self.pose[j][e])
                    # self.frontal_id[j].append(self.identity[j][e])
                    self.frontal_name[j].append(self.name[j][e])
                else:
                    self.profile_image[j].append(self.image[j][e])
                    # self.real_profile_pose[j].append(self.pose[j][e])
                    self.profile_id[j].append(self.identity[j][e])
                    self.profile_name[j].append(self.name[j][e])
            self.frontal_image[j] = torch.squeeze(
                torch.stack(self.frontal_image[j], dim=0))
            self.profile_image[j] = torch.squeeze(
                torch.stack(self.profile_image[j], dim=0))
            # self.real_frontal_pose[j] = torch.LongTensor(self.real_frontal_pose[j])
            # self.real_profile_pose[j] = torch.LongTensor(self.real_profile_pose[j])
            # self.frontal_id[j] = torch.LongTensor(self.frontal_id[j])
            self.profile_id[j] = torch.LongTensor(self.profile_id[j])
            x = torch.split(self.identity[j], 1)
            self.identity[j] = torch.cat((self.identity[j], x[0]), 0)
            if self.is_Train:
                self.batchsize.append((self.pose[j]).size(0))
            else:
                self.batchsize.append((self.profile_id[j]).size(0))
            self.rand_pose.append(
                torch.LongTensor(
                    np.random.randint(self.N_p, size=self.batchsize[j] + 1)))
            self.frontal_pose.append(torch.ones(self.batchsize[j] + 1).long())
            x = torch.split(self.profile_id[j], 1)
            self.profile_id[j] = torch.cat((self.profile_id[j], x[0]), 0)
            if self.is_Train:
                self.input_pose.append(one_hot(self.rand_pose[j], self.N_p))
            else:
                self.input_pose.append(one_hot(self.frontal_pose[j], self.N_p))

            self.fake_identity.append(
                torch.zeros(self.batchsize[j] + 1).long())  # 0 indicates fake
            self.noise.append(
                torch.FloatTensor(
                    np.random.normal(loc=0.0,
                                     scale=0.3,
                                     size=(self.batchsize[j] + 1, self.N_z))))

            #cuda
            if self.opt.gpu_ids:
                self.image[j] = self.image[j].cuda()
                self.pose[j] = self.pose[j].cuda()
                self.rand_pose[j] = self.rand_pose[j].cuda()
                self.frontal_pose[j] = self.frontal_pose[j].cuda()
                self.input_pose[j] = self.input_pose[j].cuda()
                self.identity[j] = self.identity[j].cuda()
                self.fake_identity[j] = self.fake_identity[j].cuda()
                self.noise[j] = self.noise[j].cuda()
                self.frontal_image[j] = self.frontal_image[j].cuda()
                self.profile_image[j] = self.profile_image[j].cuda()
                # self.real_frontal_pose[j] = self.real_frontal_pose[j].cuda()
                # self.real_profile_pose[j] = self.real_profile_pose[j].cuda()
                # self.frontal_id[j] = self.frontal_id[j].cuda()
                self.profile_id[j] = self.profile_id[j].cuda()

            self.image[j] = Variable(self.image[j])
            self.pose[j] = Variable(self.pose[j])
            self.rand_pose[j] = Variable(self.rand_pose[j])
            self.frontal_pose[j] = Variable(self.frontal_pose[j])
            self.input_pose[j] = Variable(self.input_pose[j])
            self.identity[j] = Variable(self.identity[j])
            self.fake_identity[j] = Variable(self.fake_identity[j])
            self.noise[j] = Variable(self.noise[j])
            self.frontal_image[j] = Variable(self.frontal_image[j])
            self.profile_image[j] = Variable(self.profile_image[j])
            # self.real_frontal_pose[j] = Variable(self.real_frontal_pose[j])
            # self.real_profile_pose[j] = Variable(self.real_profile_pose[j])
            # self.frontal_id[j] = Variable(self.frontal_id[j])
            self.profile_id[j] = Variable(self.profile_id[j])