Randomly samples input feature collection. Args: features: [N x D]
(
self, features: Union[torch.Tensor, np.ndarray]
)
| 176 | super().__init__(percentage) |
| 177 | |
| 178 | def run( |
| 179 | self, features: Union[torch.Tensor, np.ndarray] |
| 180 | ) -> Union[torch.Tensor, np.ndarray]: |
| 181 | """Randomly samples input feature collection. |
| 182 | |
| 183 | Args: |
| 184 | features: [N x D] |
| 185 | """ |
| 186 | num_random_samples = int(len(features) * self.percentage) |
| 187 | subset_indices = np.random.choice( |
| 188 | len(features), num_random_samples, replace=False |
| 189 | ) |
| 190 | subset_indices = np.array(subset_indices) |
| 191 | return features[subset_indices] |
no outgoing calls