Esempio n. 1
0
    def init_label_function(self, train_x):
        # Allocate label function
        self.y = TensorList([
            x.new_zeros(self.params.sample_memory_size, 1, x.shape[2],
                        x.shape[3]) for x in train_x
        ])

        # Output sigma factor
        output_sigma_factor = self.fparams.attribute('output_sigma_factor')
        self.sigma = (self.feature_sz / self.img_support_sz *
                      self.base_target_sz
                      ).prod().sqrt() * output_sigma_factor * torch.ones(2)

        # Center pos in normalized coords
        target_center_norm = (self.pos - self.pos.round()) / (
            self.target_scale * self.img_support_sz)

        # Generate label functions
        for y, sig, sz, ksz, x in zip(self.y, self.sigma, self.feature_sz,
                                      self.kernel_size, train_x):
            center_pos = sz * target_center_norm + 0.5 * torch.Tensor(
                [(ksz[0] + 1) % 2, (ksz[1] + 1) % 2])
            for i, T in enumerate(self.transforms[:x.shape[0]]):
                sample_center = center_pos + torch.Tensor(
                    T.shift) / self.img_support_sz * sz
                y[i, 0,
                  ...] = dcf.label_function_spatial(sz, sig, sample_center)

        # Return only the ones to use for initial training
        return TensorList(
            [y[:x.shape[0], ...] for y, x in zip(self.y, train_x)])
Esempio n. 2
0
 def get_label_function(self, sample_pos, sample_scale):
     # Generate label function
     train_y = TensorList()
     target_center_norm = (self.pos - sample_pos) / (sample_scale * self.img_support_sz)
     for sig, sz, ksz in zip(self.sigma, self.feature_sz, self.kernel_size):
         center = sz * target_center_norm + 0.5 * torch.Tensor([(ksz[0] + 1) % 2, (ksz[1] + 1) % 2])
         train_y.append(dcf.label_function_spatial(sz, sig, center))
     return train_y