Skip to content

Implementing Contrastive Self-Supervised Learning with Radiation Augmentations, SimCLR, PyTorch Lightning, and Hyperparameter Optimization - #52

Draft
stompsjo wants to merge 57 commits into
mainfrom
contrastive
Draft

Implementing Contrastive Self-Supervised Learning with Radiation Augmentations, SimCLR, PyTorch Lightning, and Hyperparameter Optimization#52
stompsjo wants to merge 57 commits into
mainfrom
contrastive

Conversation

@stompsjo

Copy link
Copy Markdown
Collaborator

I have pushed stompsjo/RadClass:contrastive to cnerg/RadClass:contrastive. I will closed#48 and copy its contents here for review. This PR should be reviewed after #49, #50, #51.

This PR constitutes the bulk of my code (excluding notebooks used to generate and analyze results) used in my dissertation. Some highlights:

  • Augmentations for gamma radiation spectra (augs.py) including a way to use them in contrastive learning (transforms.py).
  • Basic infrastructure for creating a PyTorch/Lightning (ann.py/lightModel.py) multilayer perceptron (LinearNN) and convolutional neural network (ConvNN), and a projection head (critic.py).
  • A self-/semi-supervised contrastive learning training script written for both PyTorch (SlimCLR.py) and PyTorch Lightning (SlimCLRLight.py) using the package pytorch-learning-metrics for a normalized cross-entropy loss function based on SimCLR.
  • Scripts for conducting hyperparameter optimization on the base encoder (SSLHyperOpt.py) and the projection head (ProjHyperOpt.py) using the package hyperopt.
  • A snapshot of the conda/python environment I used for my research (contrastive-environment.yml).

There is a lot of code in this branch, so it will undoubtedly make sense to split it up. I also need to clean up scripts. Many include functions that I ended up not using, or were borrowed from other people (e.g. specTools.py from Ken) and require proper attribution. If we want to move to review and merge this PR, we should probably finish reviewing and merging the preliminary work PRs in #42, #44, #45, #46.

  • Add unit tests

Jordan Stompsand others added 25 commits October 31, 2022 14:10
author Jordan Stomps <stomps@wisc.edu> 1666192691 -0400
committer Jordan Stomps <stomps@wisc.edu> 1691503697 -0400
removing accidental jupyter notebook inclusion
implementing contrastive learning with pytorch lightning, pytorch-metric-learning, and designed augmentations
creating background augmentation
adding sig2bckg augmentation
adding masking augmentation
testing an implementation of gain shift
formalizing gain-shift method in augmentation class
adding fit functions and implementation for resolution augmentation
experimenting with new gain shift
correcting positive gain drift formulation
adding resampler as second candidate for drift
adding gain-shift algorithm
manual testing
adding resampling noise to resolution transformation
rough draft nuclear interactions
complete design of nuclear interactions
condensing gain_shift algorithms
cleaning and finalizing docs for gain_shift
addressing edge cases with DANSE.resolution
[WIP] attempting to improve escape peak intensities
correcting fit roi for nuclear interactions
bug fix for mask augmentation
adding a peak count conservation method to resolution augmentation
adding init to scripts folder
overhaul of augmentations to address experience in example use
expect background spectra to be resampled before being used
initializing necessary PyTorch and SimCLR scripts
collecting more NT-Xent implementations
making classes for augmentations and data management
finish draft adaptation for minos
WIP bugfixing dry run
hunting a float/long type error
debugging projection head output
debugged ballooning representations and supervised raw_scores; learning rates too high
adding ability for different minos data
major refactor to pytorch-metric-learning by Kevin Musgrave
churning results and adding projection head
saving pytorch lightning implementation
adding functionality for background subtraction in contrastive learning
pep8
bug fixing semi-supervised labeled loss alpha scaling term
changing resample from Poisson->Binomial
bugfixing and removing extraneous print statements
adding effective learning rate for small batch size and potential functionality for projection head EMA
added some functionalities for using AdamW instead of LARS
adding input arg for specifying augmentations
adjusting syntax errors
adding CNN functionality
working functionality for squeezing vectors dependent on convolution
using os
catching missing max pooling
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@stompsjo