MCPcopy Create free account
hub / github.com/amazon-science/patchcore-inspection / run

Method run

src/patchcore/sampler.py:178–191  ·  view source on GitHub ↗

Randomly samples input feature collection. Args: features: [N x D]

(
        self, features: Union[torch.Tensor, np.ndarray]
    )

Source from the content-addressed store, hash-verified

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]

Callers 1

test_random_samplingFunction · 0.95

Calls

no outgoing calls

Tested by 1

test_random_samplingFunction · 0.76