-
Notifications
You must be signed in to change notification settings - Fork 7
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
NF: Visualize the latent space #245
base: master
Are you sure you want to change the base?
Conversation
Hello @levje, Thank you for updating ! There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2024-11-08 16:45:44 UTC |
@EmmaRenauld if you have an idea on how I could implement commit f0973ff differently, please let me know. It's a little "à bric-à-brac". |
After a few rounds of cleanup and after our discussion this Thursday about the utility of visualizing the current latent space evolution, I stripped the code to only print the latent space of the best epoch. So, each time we get a new best epoch, the latent space will be plotted and saved. This simplifies the code a lot and makes it simpler and more reusable. To plot "when a new best epoch found", I figured it would be a lot cleaner if I just have a function that can be called within the BestEpochMonitor, which is the newest addition to the modifications we talked about. It should also now be fine whenever we don't specify any data_per_streamline in the HDF5 file (there will only be one color) and it will also work if you don't specify the bundle_index. @arnaudbore, from what I tested, Fibercup should be working fine now, let me know otherwise. Finally, just to make it clear, I modified the structure of the HDF5 to have a group '<subject-id>/target/data_per_streamline/bundle_index'. Each entry/dataset within the data_per_streamline group in the HDF5 will be loaded in the dictionary as a numpy array to be included in the returned sft. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of having the color class in the latent space one, also looking at the output I feel like the colors could also be better chosen. Apart from that LGTM !
[WIP] Add Francois code to use more diverse colors
Description
It was asked to be able to visualize the latent space based on #220 w.r.t to FINTA from Legarreta et al (2021). As in the original paper, we are projecting the latent space coming out of the auto-encoder into 2D using t-SNE which preserves a smaller distance for similar streamlines and a higher distance for different streamlines.
The class latent_streamlines.py:BundlesLatentSpaceVisualizer is the bulk of the changes done and was made to potentially be reused for other data that needs to be projected and plotted in 2D. Each time we reach an epoch where the loss is minimal compared to what we encountered so far, we plot the latent space of that new epoch.
(Having a future PR adding hooks everywhere in the trainer/models in a similar fashion to LightningAI or PyTorch.nn.Module would add more flexibility to the library in my opinion!)
Scripts:
--viz_latent_space
.Testing data and script
Have you
People this PR concerns
@arnaudbore @AntoineTheb