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

Tensorboard projector for contrastive learning for embedding visualization #217

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

edyoshikun
Copy link
Contributor

@edyoshikun edyoshikun commented Jan 3, 2025

This PR adds the ability to save the embeddings and see them as a projection in tensorboard.

  • Prototype to add things to the tensorboard projection
  • Write a method to see how the embeddings evolves per epoch (Embeddings per epoch are saved in different .tsv)
  • Add additionally labels to color and filter the embeddings for interoperability (See anchor/positive pair coloring)

Screenshot 2025-01-02 at 5 37 49 PM
Screenshot 2025-01-06 at 9 35 00 AM

@ziw-liu ziw-liu linked an issue Jan 3, 2025 that may be closed by this pull request
@ziw-liu ziw-liu added enhancement New feature or request representation Representation learning (SSL) labels Jan 3, 2025
@edyoshikun edyoshikun marked this pull request as ready for review January 6, 2025 17:38
viscy/representation/engine.py Show resolved Hide resolved
labels = torch.cat((indices, indices))
# Note: we assume the two augmented views are the anchor and positive samples
embeddings = torch.cat((anchor_projection, positive_projection))
loss = self.loss_function(embeddings, labels)
self._log_step_samples(batch_idx, (anchor, pos_img), "val")

# Store embeddings for visualization
if self.current_epoch % self.embedding_log_interval == 0 and batch_idx == 0:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ziw-liu I was only logging the first batch and only from the validation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that always be the first time point(s) then?

@edyoshikun edyoshikun changed the title adding prototype for tensoboard projector to visualize the embeddings with UMAP,TSNE, PCA/ Tensorboard projector for contrastive learning for embedding visualization Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request representation Representation learning (SSL)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log embeddings in TensorBoard
2 participants