def nearest_neighbors(self, embedding, n_neighbors: int=9):
        """Compare embedding Features with the memory bank to get Nearest Neighbours distance
        """
        B, HW, C = embedding.shape
        n_coreset = self.memory_bank.shape[0]
        distances = []  # paddle.zeros((B, HW, n_coreset))
        for i in range(B):
            distances.append(
                cdist(
                    embedding[i, :, :], self.memory_bank,
                    p=2.0))  # euclidean norm
        distances = paddle.stack(distances, 0)
        distances, _ = distances.topk(k=n_neighbors, axis=-1, largest=False)
        return distances  # B,
Compare embedding Features with the memory bank to get Nearest Neighbours distance
        
contrib/QualityInspector/qinspector/uad/models/patchcore.py