Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code attribution #78

Closed
rvorias opened this issue Jan 18, 2022 · 3 comments
Closed

Code attribution #78

rvorias opened this issue Jan 18, 2022 · 3 comments

Comments

@rvorias
Copy link

rvorias commented Jan 18, 2022

Hi,

Your implementation of PatchCore coreset selection:

def create_coreset(

is VERY similar to my implementation, which I have designed and coded from scratch:
https://github.com/rvorias/ind_knn_ad/blob/57de628b334f9dd62316ac7770db6e963b71ee8e/indad/utils.py#L36

Please elaborate on this.

More details:
this repo:

        select_idx = 0
        last_item = sample_set[select_idx : select_idx + 1]
        coreset_idx = [torch.tensor(select_idx).to(embedding.device)]  # pylint: disable=not-callable
        min_distances = torch.linalg.norm(sample_set - last_item, dim=1, keepdims=True)

        for _ in range(sample_count - 1):
            distances = torch.linalg.norm(sample_set - last_item, dim=1, keepdims=True)  # broadcast
            min_distances = torch.minimum(distances, min_distances)  # iterate
            select_idx = torch.argmax(min_distances)  # select

            last_item = sample_set[select_idx : select_idx + 1]
            min_distances[select_idx] = 0
            coreset_idx.append(select_idx)

        coreset_idx = torch.stack(coreset_idx)
        self.memory_bank = embedding[coreset_idx]

my repo:

    select_idx = 0
    last_item = z_lib[select_idx:select_idx+1]
    coreset_idx = [torch.tensor(select_idx)]
    min_distances = torch.linalg.norm(z_lib-last_item, dim=1, keepdims=True)
    # The line below is not faster than linalg.norm, although i'm keeping it in for
    # future reference.
    # min_distances = torch.sum(torch.pow(z_lib-last_item, 2), dim=1, keepdims=True)
    
    ...
    
    for _ in tqdm(range(n-1), **TQDM_PARAMS):
        distances = torch.linalg.norm(z_lib-last_item, dim=1, keepdims=True) # broadcasting step
        # distances = torch.sum(torch.pow(z_lib-last_item, 2), dim=1, keepdims=True) # broadcasting step
        min_distances = torch.minimum(distances, min_distances) # iterative step
        select_idx = torch.argmax(min_distances) # selection step

        # bookkeeping
        last_item = z_lib[select_idx:select_idx+1]
        min_distances[select_idx] = 0
        coreset_idx.append(select_idx.to("cpu"))

    return torch.stack(coreset_idx)
@samet-akcay
Copy link
Contributor

Hi @rvorias, thank you for notifying us. This was a PR that was merged 4 hours ago. I agree that this should have been scanned before merging. I'll revert this PR right now. Apologies.

@rvorias
Copy link
Author

rvorias commented Jan 18, 2022

I wish to let the open-source community prosper, but I demand attribution.

@samet-akcay
Copy link
Contributor

Can't agree more! As I said, we perform scans before we merge, which we didn't do this time, and this happened. This has now been reverted. Apologies again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants