Skip to content

About Visualization Code #5

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

Open
viperdosth opened this issue Jul 30, 2024 · 1 comment
Open

About Visualization Code #5

viperdosth opened this issue Jul 30, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@viperdosth
Copy link

Good Work!
But could you provide the code for visualization of patch embeddings which shown in Fig.4 in your paper.
Thanks a lot.

@caoyunkang
Copy link
Owner

Thank you for your interest! I apologize for the current state of the visualization code—it’s still somewhat unorganized, and I haven't had the time to properly restructure it. However, I’m attaching the core part of the code below for your reference. I hope this helps to address your issue:

    def visualize_feat_map(self, patch_tokens):
        concat_patch_tokens = torch.cat(patch_tokens, dim=2)
        B, L, C = concat_patch_tokens.shape
        H = int(np.sqrt(L))
        concat_patch_tokens = concat_patch_tokens.squeeze(0).cpu().numpy()

        n_components = 1
        F_reshaped = concat_patch_tokens.reshape(-1, C)
        pca = PCA(n_components=n_components)
        F_pca = pca.fit_transform(F_reshaped)

        scaler = MinMaxScaler()
        F_pca_normalized = scaler.fit_transform(F_pca)

        visualized_image = F_pca_normalized.reshape(H, H, n_components)

        visualized_image = visualized_image * 255
        visualized_image = visualized_image.astype(np.uint8)

        return visualized_image

@caoyunkang caoyunkang added the enhancement New feature or request label Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants