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

Merging mass-mapping to main #3

Open
wants to merge 436 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
436 commits
Select commit Hold shift + click to select a range
a0fd6c7
Merge branch 'radio' of https://github.com/astro-informatics/rcGAN in…
Oct 27, 2023
33beb84
ignore slurm output files
tobias-liaudat Oct 27, 2023
a865c73
change jobs dirs
tobias-liaudat Oct 27, 2023
c850275
delete old jobs (changed dir)
tobias-liaudat Oct 27, 2023
2a60244
Merge branch 'radio' of https://github.com/astro-informatics/rcGAN in…
tobias-liaudat Oct 27, 2023
91be170
Change discriminator to work with any image size
MatthijsMars Oct 27, 2023
cff2bde
Merge branch 'radio' of github.com:astro-informatics/rcGAN into radio
MatthijsMars Oct 27, 2023
c0cd7dc
Merge branch 'radio' of https://github.com/astro-informatics/rcGAN in…
tobias-liaudat Oct 27, 2023
bc01aba
Refactor im_size in test.py
Oct 27, 2023
4ffad34
update config files with new format
tobias-liaudat Oct 27, 2023
982dc73
refactor parser
tobias-liaudat Oct 27, 2023
db59207
refactor train script for better config handling
tobias-liaudat Oct 27, 2023
ab33eb4
Clean discriminator
tobias-liaudat Oct 27, 2023
54c9325
update comments
tobias-liaudat Oct 27, 2023
79e0335
Merge branch 'dev' of https://github.com/astro-informatics/rcGAN into…
tobias-liaudat Oct 27, 2023
0c6d8d3
Refactors image_size in test.py
Oct 27, 2023
e3ea9cc
Merge branch 'dev' of https://github.com/astro-informatics/rcGAN into…
Oct 27, 2023
8b0a448
clean generator UNet
tobias-liaudat Oct 27, 2023
56d7c0f
Refactor config path
Oct 27, 2023
e0aff25
Merge branch 'dev' of https://github.com/astro-informatics/rcGAN into…
Oct 27, 2023
eaf9304
move script to mass mapping
tobias-liaudat Oct 27, 2023
0ab2179
Merge branch 'dev' of https://github.com/astro-informatics/rcGAN into…
tobias-liaudat Oct 27, 2023
2f5ef01
Renaming all im_size variables to same variable
Oct 27, 2023
f84d814
Merge branch 'dev' of https://github.com/astro-informatics/rcGAN into…
Oct 27, 2023
6884078
Refactors image size in data module
Oct 27, 2023
22da7c6
Remove old TODO
Oct 27, 2023
33b841e
Refactors config file in script
Oct 27, 2023
40c57cb
Delted unneccesary file
Oct 27, 2023
8b9da61
Additional documentation on variable types.
Oct 27, 2023
10e5feb
Removes old TODO
Oct 27, 2023
81f6410
Delete old one-time script
Oct 27, 2023
6100a94
Deletes old image
Oct 27, 2023
aabf6f8
Saves mask
JessWhitney Oct 27, 2023
4068f7f
New TODO
Oct 27, 2023
623fa47
Saving noise standard devs
JessWhitney Oct 27, 2023
2a50ab5
Editing dataset noise creator
Oct 27, 2023
7a3eadd
update test
tobias-liaudat Oct 27, 2023
a4ef3c1
add test for radio
tobias-liaudat Oct 27, 2023
da198b8
update forward model to handle realistic cosmos scenario
tobias-liaudat Oct 27, 2023
a9bb75f
Merge branch 'dev' of https://github.com/astro-informatics/rcGAN into…
tobias-liaudat Oct 27, 2023
dd27f01
crop cosmos data to 300x300
tobias-liaudat Oct 27, 2023
0448119
Creates script to generate new cosmos-like dataset
Oct 27, 2023
0fef025
Merge branch 'dev' of https://github.com/astro-informatics/rcGAN into…
Oct 27, 2023
e64beb4
Created slurm file for data generation
Oct 27, 2023
3879ffe
Saves new convergence files
Oct 27, 2023
6f945b9
Sorts data into train/test/val
Oct 27, 2023
458d2bb
New method to shuffle maps
JessWhitney Oct 30, 2023
040d790
Corrects range for paths
Oct 30, 2023
4552e79
Complete script to create new dataset
Oct 31, 2023
2388783
Updates config file for new training
Nov 1, 2023
c0c752d
Updates slurm commands
Nov 1, 2023
eb2d0ba
Code to crop kappa files to required size
Nov 1, 2023
e567def
Removes old debugging script
Nov 2, 2023
1a66bb5
Matches naming convention of kappa files
Nov 2, 2023
bc7a8f6
Correctly parses config arg - no ''
Nov 2, 2023
160f6b6
Moved cropper.py to a new directory and modified dataset_creation_not…
Nov 2, 2023
5a6ec55
Moved cropper to new directory
Nov 2, 2023
4c3b202
Moved kappa_selection.py to a new location
Nov 2, 2023
42d037f
Moved location of pre-processing mass_mapping script.
Nov 2, 2023
a1cd6c1
Creates a single COSMOS data generation script
Nov 2, 2023
f27943d
Corrects directory in slurm file
Nov 2, 2023
bb73623
Moved files to scripts directory
Nov 2, 2023
b48afb3
Add TODO
Nov 2, 2023
340d3e7
Corrects slurm file
Nov 6, 2023
a1ad36b
Slurm change
Nov 7, 2023
0ff1894
fix argument bug
tobias-liaudat Nov 7, 2023
6f4b9ae
Reorder files
tobias-liaudat Nov 7, 2023
07bf73a
Adds cosmos_dir_path to config file
Nov 7, 2023
031d0a2
Fixing mask bug that didn't account for additional dimension of input…
Nov 7, 2023
d76d7bb
Masks areas where mask = true not mask = false
Nov 7, 2023
8f083e5
adds config arg to slurm file
Nov 8, 2023
4379995
Adds end_epoch variable
Nov 8, 2023
597b80e
Adjusting plotting function for new image size
Nov 8, 2023
24fabe5
Add changes to scale the effective batch size of the model
MatthijsMars Nov 9, 2023
9c8555e
add multi-gpu documentation and example slurm scripts
MatthijsMars Nov 13, 2023
b3f2dcd
Update comments with links to multi-gpu files
MatthijsMars Nov 13, 2023
e218d1a
Adds indication of mask to plots
Nov 14, 2023
a54baf4
Merge pull request #2 from astro-informatics/dev-multiGPU
tobias-liaudat Nov 14, 2023
edb00b3
Alters width of mask contour
Nov 15, 2023
f8f7457
Adds utils for Kaiser-squires plots
Nov 15, 2023
18c4529
Merge branch 'dev' of https://github.com/astro-informatics/rcGAN into…
Nov 15, 2023
7a7eae6
Fixes aspect ratio of ks figure
Nov 15, 2023
739ccb1
Adds unsmoothed ks to plot
Nov 20, 2023
67810e2
Adds better kaiser-squires function for plotting
Nov 20, 2023
35a615e
Change ks function for plotting
Nov 22, 2023
9939eed
Change save format for cosmos e1 e2
Nov 22, 2023
d6c237d
Adding cosmos shear map
Nov 24, 2023
93e1778
Syncing test notebooks
Nov 24, 2023
34a2862
Syncing test notebooks
Nov 24, 2023
6dd22f1
Removes unused import
Nov 24, 2023
37d380c
Adds wip script for creating cosmos plot
Nov 24, 2023
830ad72
Edits to cosmos plot
JessWhitney Nov 28, 2023
9fa1531
Transforms and permutes cosmos shear to tensor
Nov 28, 2023
70dc2ac
Generates cosmos samples
Nov 29, 2023
5f76ee2
Plotting tests in jyputer notebook
Nov 29, 2023
fc21a82
Cosmos samples
Nov 29, 2023
1007bc2
Corrections to Gaussian_smoothing function
Nov 29, 2023
91c4757
Modifies docstrings for smoothing function
Nov 29, 2023
cbd4c4a
Corrected samples
Nov 29, 2023
510c074
Keeps calculations all one single device
Nov 29, 2023
d28c15c
Extra COSMOS plots
Dec 12, 2023
0e4d9f1
Updates notebooks
Dec 13, 2023
12febf1
Adds cosmos vertices
JessWhitney Dec 15, 2023
38e9f91
Syncing notebooks
Dec 15, 2023
e9d5538
Syncing notebooks
Dec 15, 2023
803dcac
Changes some plot axes to RA, DEC
Dec 15, 2023
ae8314b
All cosmos plots now have ra,dec axes.
Dec 18, 2023
e340c4f
Temporary notebook to debug Kaiser-Squires
JessWhitney Jan 10, 2024
939aefd
Changes function for backward model
JessWhitney Jan 10, 2024
d5db4e7
More debugging plots
JessWhitney Jan 10, 2024
33e4ae2
Kaiser-squires debugging
Jan 12, 2024
80e47f0
COSMOS debugging
JessWhitney Jan 15, 2024
ce3295a
Syncing notebooks
JessWhitney Jan 15, 2024
813db7d
Uses scipy smoothing, and backward_model rather than ks93 for Kaiser-…
Jan 15, 2024
1a27b3b
Syncing notebooks
Jan 16, 2024
951b8b1
Testing fourier kernel
Jan 17, 2024
23f8a7d
Correcting kernel function
Jan 17, 2024
8df820f
Corrects error in kernel definition
Jan 18, 2024
6f84dfc
Finished debugging the Kaiser-Squires function
Jan 18, 2024
e38c7c8
Not using Gaussian_smoothing function for now
Jan 18, 2024
ef63b54
Removes unused script
Jan 18, 2024
9615931
Removes unused imports, unifies fig sizes and vmin/max limits
Jan 18, 2024
c2500f4
Updated cosmos samples
Jan 29, 2024
ec7c896
Renaming save figs
Jan 29, 2024
f8359f2
New results notebook
Jan 29, 2024
a000cdd
Test mirroring vertices
JessWhitney Jan 29, 2024
741aa00
New cosmos plots and graph rotations
Jan 31, 2024
2e08d65
Makes it easier to switch directory
JessWhitney Feb 2, 2024
2b231a7
Adds xray data
JessWhitney Feb 2, 2024
39f3716
Test - no rotation
JessWhitney Feb 2, 2024
604ebca
Update titles
Feb 21, 2024
f4bf412
Adds time functions
Feb 21, 2024
6f40477
Adds time
Feb 21, 2024
10c1574
Correctly takes real component in plots
Mar 1, 2024
c314d1d
Slurm script changes
JessWhitney Mar 5, 2024
a97dcd3
Removes .abs()
JessWhitney Mar 5, 2024
5afff1c
New notebook for GIFS
JessWhitney Mar 5, 2024
97053c0
Fixes tensor size bug
JessWhitney Mar 5, 2024
bde5273
Up to date notebooks
JessWhitney Mar 6, 2024
7049fb9
Uses start epoch in loop
JessWhitney Mar 12, 2024
44e483a
Replaces .abs() with real numpy component
JessWhitney Mar 12, 2024
bfbf5b4
New normalisation for complex shear
JessWhitney Mar 18, 2024
b9a5fc9
wip normalising function for shear
JessWhitney Mar 18, 2024
252e078
New normalisation
JessWhitney Mar 18, 2024
b5f26c6
Removes unused function
JessWhitney Mar 18, 2024
436c38a
Swaps .abs() with .real()
JessWhitney Mar 18, 2024
05fad96
Adds precomputed mean/std values
JessWhitney Mar 18, 2024
c43347f
Moves mean/std to parameters rather than hardcoded vals
JessWhitney Mar 18, 2024
5b47cc3
Adds function to normalise complex inputs
JessWhitney Mar 21, 2024
512c105
Removes unused lines
JessWhitney Apr 16, 2024
2170788
Adds normalisation to slurm file
JessWhitney Apr 16, 2024
dadae50
Syncing notebooks
JessWhitney Apr 16, 2024
8e4f175
Plot now uses convergence mean/std not shear
JessWhitney Apr 16, 2024
bb03abc
Removes unused import
JessWhitney Apr 16, 2024
2f2598b
No longer need mean,std.cuda as they are floats
JessWhitney Apr 16, 2024
453827c
Removes debugging config files
JessWhitney Apr 17, 2024
67f9ffa
Removes todos
JessWhitney Apr 17, 2024
8ccaab3
Replaces .abs with .real
JessWhitney Apr 17, 2024
d110a3d
Removes old slurm file
JessWhitney Apr 17, 2024
125b1ff
Cleaning up, adding todos
JessWhitney Apr 17, 2024
136caf7
Cleaning up sample files
JessWhitney Apr 17, 2024
9349c97
Uses kappa mean/std instead of gamma mean/std
JessWhitney Apr 17, 2024
937fc30
Removes old files
JessWhitney Apr 17, 2024
ce70928
Refactors kappa mean/std
JessWhitney Apr 17, 2024
671c567
Makes notebook for plotting figures fo sims.
JessWhitney Apr 18, 2024
9e71f04
TODOs for gifs
JessWhitney Apr 18, 2024
4c42283
Added new function for complex mean/std, and updated usage
JessWhitney Apr 19, 2024
86e8f04
Add new function to unnormalise complex data
JessWhitney Apr 19, 2024
71215fc
Correct typo
JessWhitney Apr 19, 2024
fdbe4fc
Calls correct mean/std
JessWhitney Apr 19, 2024
73df881
Merge branch 'dev' of https://github.com/astro-informatics/rcGAN into…
JessWhitney Apr 19, 2024
2e4d9cb
Imports from correct file now
JessWhitney Apr 19, 2024
b5174bf
Splits plot script into sample generation, and figure notebook
JessWhitney Apr 24, 2024
796d4be
New normalisation
JessWhitney Apr 24, 2024
ebfcf08
Loads kappa_mean/std as tensor with dimension 1
JessWhitney Apr 24, 2024
7b03eed
Adds code to create gif of simulations
JessWhitney Apr 24, 2024
0942ace
Updates indexing of samples
JessWhitney Apr 24, 2024
c2ff13a
Ensures tensors are on same device
JessWhitney Apr 25, 2024
cdf0a6a
Changes wandb logging
JessWhitney Apr 25, 2024
da87b31
Fixes indexing for mean/std in get_embed_im
JessWhitney May 3, 2024
2540a10
Picks more suitable range of epochs for validation; no longer deletes…
JessWhitney May 3, 2024
1d3ceb0
Normalisation testing
JessWhitney May 8, 2024
8cbe51a
Permutes unnormalised data to match expectations
JessWhitney May 8, 2024
246314b
Removes unused imports
JessWhitney May 8, 2024
f500a7f
Adds batch size dimension
JessWhitney May 8, 2024
4ffb0b6
syncing jupyter notebooks
JessWhitney May 10, 2024
b03a4bc
KS pearson coefficient calculation
JessWhitney May 16, 2024
4d94d39
Adds rmse calculation
JessWhitney May 16, 2024
9cec270
Syncing all notebooks for offline work
JessWhitney Jun 12, 2024
467480d
swithces pearson and psnr to skimage functions
JessWhitney Jun 12, 2024
7eb8588
Adds torch.no_grad() fix to cosmos samp generator
JessWhitney Jun 12, 2024
7b3b72d
Adds notebook to test metrics
JessWhitney Jun 17, 2024
08f3229
Clarification text on KS for metric notebook
JessWhitney Jun 17, 2024
e2de336
Adds metric functions to mass map utils
JessWhitney Jun 27, 2024
4c312f1
Updates validation to include other metrics
JessWhitney Jun 28, 2024
667f6bf
Adds table to track metrics for each epoch
JessWhitney Jun 28, 2024
493b78a
Fixes problems loading mask in val file
JessWhitney Jul 1, 2024
e23b534
Turns util functions into torch functions not numpy
JessWhitney Jul 2, 2024
e20bfb1
syncing notebooks to edit offline
JessWhitney Jul 4, 2024
112409d
Deletes old redundant jupyter notebooks
JessWhitney Jul 4, 2024
d2b813a
Makes new self contained cosmos notebook
JessWhitney Jul 5, 2024
08ba1bc
Collates cosmos sampling and plotting to one notebook
JessWhitney Jul 17, 2024
a59620c
Removes section that was testing metrics, as this is in a new noteboo…
JessWhitney Jul 17, 2024
b2040dd
Adds todos to metric notebook
JessWhitney Jul 17, 2024
19d2f74
Adds Kaiser-squires as input channel
JessWhitney Aug 6, 2024
747f58a
Adds config file for testing args
JessWhitney Sep 2, 2024
1054da5
Bugfix input channels 3->4 (Re and Im part of KS map)
JessWhitney Sep 2, 2024
82ae302
Adds ks map to GAN input
JessWhitney Sep 2, 2024
e13d5f3
Validate.py now automatically defines final epoch
JessWhitney Sep 2, 2024
067a39e
Syncs testing notebooks
JessWhitney Sep 2, 2024
fbd1636
Updates experience name
JessWhitney Sep 2, 2024
d33c269
Syncing val test notebook
JessWhitney Sep 2, 2024
e12ac49
Made metrics script to test metrics across test maps
JessWhitney Sep 26, 2024
dc3e63b
No longer using cfid for validation
JessWhitney Oct 10, 2024
d2b2408
Validating using pixel image not embedded image
JessWhitney Oct 10, 2024
bdc8705
Uses our own psnr function
JessWhitney Oct 10, 2024
e129df6
Fixes bug with saving metrics
JessWhitney Oct 10, 2024
be91b63
Updates notebooks
JessWhitney Oct 10, 2024
4f3d46a
sigma -> sigma / sqrt(2) in noise_maker
JessWhitney Oct 11, 2024
6a2388b
Calls fourier kernel in init and updates realistic_noise_maker accord…
JessWhitney Oct 11, 2024
6257f20
Removes old files to avoid confusion
JessWhitney Oct 11, 2024
45f1a7b
Changes out_chans from 2 -> 1
JessWhitney Oct 11, 2024
c431fc1
Loads mock maps as float64 not complex128
JessWhitney Oct 11, 2024
f4dfe73
Updates for real-kappa: now in forward_model adds empty extra dimensi…
JessWhitney Oct 11, 2024
846dd4f
Ensures srcipt goes from the .dat files, like a new user would need
JessWhitney Oct 11, 2024
459cc73
Removes unused util functions
JessWhitney Oct 11, 2024
1e76e87
metrics uses ks_util functions rather than manually redefining
JessWhitney Oct 11, 2024
524550b
removes tensor_to_complex on gt and recon, since they are now real
JessWhitney Oct 11, 2024
a05d4e6
Updates slurm script to remove old unused files
JessWhitney Oct 11, 2024
8f3cffb
Fixes bug with kappa dimensions
JessWhitney Oct 11, 2024
5ed4910
adds .squeeze() when loading samples
JessWhitney Oct 11, 2024
2e0e4b0
Merge branch 'real_gan_in_and_out' of github.com:astro-informatics/rc…
JessWhitney Oct 11, 2024
e76661e
Syncing cosmos notebook
JessWhitney Oct 22, 2024
7cebbb9
Updating tensor sizes now we don't need re/im for convergence maps
JessWhitney Oct 22, 2024
770f4a3
out chans ->1 in test config
JessWhitney Oct 22, 2024
f83f6e7
Updates slurm files
JessWhitney Oct 22, 2024
4d04fe3
Syncing notebooks
JessWhitney Oct 22, 2024
fc19b5d
Merge branch 'real_gan_in_and_out' of https://github.com/astro-inform…
JessWhitney Oct 22, 2024
543d5ef
Adds mass-mapping info to read me
JessWhitney Nov 1, 2024
830981c
Deletes test config file
JessWhitney Nov 1, 2024
10d0cbe
Adds save path for figures to config
JessWhitney Nov 1, 2024
d81e240
Makes a basic mass_mapping.md
JessWhitney Nov 1, 2024
ddefdcd
Removes old piece of data
JessWhitney Nov 1, 2024
dea55b0
Removes old unused todo list
JessWhitney Nov 1, 2024
8c27c4c
Removes outdated preprocessing script
JessWhitney Nov 1, 2024
1e83446
Adds basic description of preprocessing script
JessWhitney Nov 1, 2024
c47a73d
Parses paths as args rather than manually defining
JessWhitney Nov 1, 2024
f299b53
Removes old torch util functions
JessWhitney Nov 1, 2024
9d12018
Adds config as args to preprocessing slurm script
JessWhitney Nov 1, 2024
42fdf29
Delete .DS_Store
JessWhitney Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
47 changes: 46 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ __pycache__/
*.DS_Store
data/*.DS_Store

*.err
*.out

# Distribution / packaging
.Python
Expand Down Expand Up @@ -134,4 +136,47 @@ venv.bak/
dmypy.json

# Pyre type checker
.pyre/
.pyre/
mock_c_map_2.png
mock_c_map.png
mock_observation_2.png
mock_observation.png
jobs/validate_test/avg_err_std_1_v2.png
jobs/validate_test/avg_err_std_2_v2.png
jobs/validate_test/avg_err_std_3_v2.png
jobs/validate_test/avg_err_std_4_v2.png
jobs/validate_test/avg_err_std_5_v2.png
jobs/validate_test/diversity_1_v2.png
jobs/validate_test/diversity_2_v2.png
jobs/validate_test/diversity_3_v2.png
jobs/validate_test/diversity_4_v2.png
jobs/validate_test/diversity_5_v2.png
jobs/validate_test/generated_samples_plots.npy
jobs/validate_test/P_ascent_1_v2.png
jobs/validate_test/P_ascent_2_v2.png
jobs/validate_test/P_ascent_3_v2.png
jobs/validate_test/P_ascent_4_v2.png
jobs/validate_test/P_ascent_5_v2.png
jobs/validate_test/P_ascent_zoom_1_v2.png
jobs/validate_test/P_ascent_zoom_2_v2.png
jobs/validate_test/P_ascent_zoom_3_v2.png
jobs/validate_test/P_ascent_zoom_4_v2.png
jobs/validate_test/P_ascent_zoom_5_v2.png
jobs/validate_test/square_1.png
jobs/validate_test/square_2.png
jobs/validate_test/square_3.png
jobs/validate_test/square_4.png
jobs/validate_test/square_5.png
jobs/validate_test/zoomed_overview_1.png
jobs/validate_test/zoomed_overview_2.png
jobs/validate_test/zoomed_overview_3.png
jobs/validate_test/zoomed_overview_4.png
jobs/validate_test/zoomed_overview_5.png
jobs/validate_test/val_test_cGAN_538273.err
jobs/validate_test/val_test_cGAN_538273.out
jobs/validate_test/val_test_cGAN_540044.err
jobs/validate_test/val_test_cGAN_540044.out
jobs/validate_test/val_test_cGAN_540048.err
jobs/validate_test/val_test_cGAN_540048.out
jobs/validate_test/val_test_cGAN_540050.err
jobs/validate_test/val_test_cGAN_540050.out
69 changes: 11 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,25 @@
# A Regularized Conditional GAN for Posterior Sampling in Inverse Problems [[arXiv]](https://arxiv.org/abs/2210.13389)
# Generative modelling for mass-mapping with fast uncertainty quantification [[arXiv]](https://arxiv.org/abs/2410.24197)
## Setup
Copy link
Member

Choose a reason for hiding this comment

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

It'd be good to add a small description of the method (something like the abstract used for the paper but more synthetic). Also select one figure from the paper to illustrate the method (I'd suggest the one from the COSMOS field showing the reconstruction and std dev).

See ```docs/setup.md``` for basic environment setup instructions.
Copy link
Member

Choose a reason for hiding this comment

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

This file does not exist


Copy link
Member

Choose a reason for hiding this comment

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

You need to add a reference to the comments.md file where we explain how to install the model and some other useful stuff. There are two option, mention what you can find on that file and provide a link or merge the info of that file in the readme

## Reproducing our Results
### MRI
See ```docs/mri.md``` for instructions on how to setup and reproduce our MRI results.

## Extending the Code
See ```docs/new_applications.md``` for basic instructions on how to extend the code to your application.
## Reproducing the our Results
Copy link
Member

Choose a reason for hiding this comment

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

typo

###
See ```docs/mass_mapping.md``` for instructions on how to setup and reproduce our COSMOS results.

Copy link
Member

Choose a reason for hiding this comment

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

Could you coordinate with Matthijs so that the radio application of the GAN is also updated on this main branch. It'd be good to have everything to reproduce the results of both papers in a single repo.

## Questions and Concerns
If you have any questions, or run into any issues, don't hesitate to reach out at [email protected].

## TODO
- [x] Migrate to PyTorch Lightning
- [x] Reimplement MRI rcGAN
- [x] Update MRI experiment to R=8
- [ ] Reimplement inpainting rcGAN
- [ ] Extend to super resolution
If you have any questions, or run into any issues, don't hesitate to reach out at [email protected]

## References
This repository contains code from the following works, which should be cited:

```
@article{zbontar2018fastmri,
title={fastMRI: An open dataset and benchmarks for accelerated MRI},
author={Zbontar, Jure and Knoll, Florian and Sriram, Anuroop and Murrell, Tullie and Huang, Zhengnan and Muckley, Matthew J and Defazio, Aaron and Stern, Ruben and Johnson, Patricia and Bruno, Mary and others},
journal={arXiv preprint arXiv:1811.08839},
year={2018}
}

@article{devries2019evaluation,
title={On the evaluation of conditional GANs},
author={DeVries, Terrance and Romero, Adriana and Pineda, Luis and Taylor, Graham W and Drozdzal, Michal},
journal={arXiv preprint arXiv:1907.08175},
year={2019}
}
This repository was forked from rcGAN by Bendel et al., with significant changes and modification made by Whitney et al.
Copy link
Member

Choose a reason for hiding this comment

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

Add link to original Bendel paper as well as the original rcGAN repo


@inproceedings{Karras2020ada,
title={Training Generative Adversarial Networks with Limited Data},
author={Tero Karras and Miika Aittala and Janne Hellsten and Samuli Laine and Jaakko Lehtinen and Timo Aila},
booktitle={Proc. NeurIPS},
year={2020}
}

@inproceedings{zhao2021comodgan,
title={Large Scale Image Completion via Co-Modulated Generative Adversarial Networks},
author={Zhao, Shengyu and Cui, Jonathan and Sheng, Yilun and Dong, Yue and Liang, Xiao and Chang, Eric I and Xu, Yan},
booktitle={International Conference on Learning Representations (ICLR)},
year={2021}
}

@misc{zeng2022github,
howpublished = {Downloaded from \url{https://github.com/zengxianyu/co-mod-gan-pytorch}},
month = sep,
author={Yu Zeng},
title = {co-mod-gan-pytorch},
year = 2022
}
```

Copy link
Member

Choose a reason for hiding this comment

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

It'd be good to add a reproducibility section and links to Zenodo. It'd be good to find there the trained GAN used to generate the results. Also, some samples and reconstructions of the GAN.

Should we include the simulations in a zenodo? It depends on the size of the sims. If they are too big, you could just upload some of them to have a representative set.

## Citation
If you find this code helpful, please cite our paper:
```
@journal{bendel2022arxiv,
author = {Bendel, Matthew and Ahmad, Rizwan and Schniter, Philip},
title = {A Regularized Conditional {GAN} for Posterior Sampling in Inverse Problems},
year = {2022},
journal={arXiv:2210.13389}
@journal{2024arxiv,
author = {Whitney, Jessica and Liaudat, Tobías and Price, Matthew and Mars, Matthijs and McEwen, Jason},
title = {Generative modelling for mass-mapping with fast uncertainty quantification},
year = {2024},
journal={arXiv:2410.24197}
}
```
60 changes: 57 additions & 3 deletions comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# rcGAN development version


# Installation

If in the Hypatia cluster, first run:
Copy link
Member

Choose a reason for hiding this comment

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

We should not mention Hypatia, but be general for a computer cluster.

``` bash
source /share/apps/anaconda/3-2022.05/etc/profile.d/conda.sh
```


First install the conda dependencies setting the correct channels:
``` bash
conda create --name cGAN --file conda_requirements.txt --channel pytorch --channel nvidia --channel conda-forge --channel defaults
Expand All @@ -26,10 +34,56 @@ configs -> `~/.config/wandb` -> `WANDB_CONFIG_DIR`

# Set the variables
``` bash
export WANDB_DIR=/share/gpu0/tl3/wandb/logs
export WANDB_CACHE_DIR=/share/gpu0/tl3/wandb/.cache/wandb
export WANDB_CONFIG_DIR=/share/gpu0/tl3/wandb/.config/wandb
export WANDB_DIR=/share/gpu0/jjwhit/wandb/logs
export WANDB_CACHE_DIR=/share/gpu0/jjwhit/wandb/.cache/wandb
export WANDB_CONFIG_DIR=/share/gpu0/jjwhit/wandb/.config/wandb
```

# Training the model

Training is as simple as running the following command:
```python
python train.py --config ./configs/mass_map.yml --exp-name rcgan_test --num-gpus X
```
where ```X``` is the number of GPUs you plan to use. Note that this project uses Weights and Biases (wandb) for logging.
See [their documentation](https://docs.wandb.ai/quickstart) for instructions on how to setup environment variables.
Alternatively, you may use a different logger. See PyTorch Lightning's [documentation](https://lightning.ai/docs/pytorch/stable/extensions/logging.html) for options.

If you need to resume training, use the following command:
```python
python train.py --config ./configs/mass_map.yml --exp-name rcgan_test --num-gpus X --resume --resume-epoch Y
```
where ```Y``` is the epoch to resume from.

By default, we save the previous 50 epochs. Ensure that your checkpoint path points to a location with sufficient disk space.
If disk space is a concern, 50 can be reduced to 25.
This is important for the next step, validation.


## Multi-GPU Runs
To make the lightning module work on multiple GPUs (and on multiple nodes) when using the SLURM workload manager, we need to be careful in setting up the SLURM job script. An example of how to do this can be found here https://pytorch-lightning.readthedocs.io/en/1.2.10/clouds/slurm.html.

In particular if we want to run on 4 GPUs on one node we need to make sure that we ask for 4 GPUs as well as 4 tasks (since lightning will create 1 task per GPU) per node:

```
#SBATCH --gres=gpu:4 # n_gpus
#SBATCH --ntasks-per-node=4 # ntasks needs to be same as n_gpus
```

An example of a job-script for training using multiple GPUs can be found in [examples/example_multi_gpu.sh](https://github.com/astro-informatics/rcGAN/blob/dev-multiGPU/examples/example_multi_gpu_train.sh)

## Batch size tuning
Additionally I have created a script, [find_batch_size.py](https://github.com/astro-informatics/rcGAN/blob/dev-multiGPU/find_batch_size.py) that finds the largest batch_size that you can run per GPU. This depends on the VRAM available on the GPU and can therefore vary accross machines/nodes. An example job file can be found in [examples/example_find_batch_size.sh](https://github.com/astro-informatics/rcGAN/blob/dev-multiGPU/examples/example_find_batch_size.sh). Usage is:

```
python find_batch_size.py --config [config_file.yml]
```

Finally, to support larger batch sizes we can accumulate the gradients over batch sizes. In order to enable this and set the amount of accumulation you can add to your config file:

```
batch_size: 8 # batch_size per GPU (because of DDP)
accumulate_grad_batches: 2 # updates model after 2 batches per GPU
```

When using the distributed data processing (DDP) training strategy, the model is copied exactly on each GPU and they all see only a part of the data during the epoch. After processing 1 batch on each of the GPUs, the gradients from each of the GPUs are averaged and the models are updated. If we use gradient accumulation the gradients are instead averaged over several of such steps. The effective batch size of the model is therefore: n_gpus * batch_size * accumulate_grad_batches.
36 changes: 36 additions & 0 deletions configs/mass_map.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#Change checkpoint and sense_map path
checkpoint_dir: /share/gpu0/jjwhit/mass_map/mm_models/ # Where model will save checkpoints
data_path: /share/gpu0/jjwhit/kappa_cosmos_simulations/cropped_dataset/ # Path to simulation dataset
cosmo_dir_path: /home/jjwhit/rcGAN/mass_map_utils/cosmos/ # Path to cosmos information such as mask
save_path: /share/gpu0/jjwhit/samples/real_output/ # where figures and samples will be saved

# Define the experience
experience: mass_mapping
kappa_mean: 0.00015744006243248638 # Value calculated during preprocessing
kappa_std: 0.02968584954283938 # Value calculated during preprocessing

# Number of code vectors for each phase
num_z_test: 32
num_z_valid: 8
num_z_train: 2

# Data
in_chans: 4 # Real+Imag parts from observation + Kaiser squires map
out_chans: 1 # A real convergence map
im_size: 300 # Pixel width/height (square iamges)

# Optimizer:
lr: 0.001
beta_1: 0
beta_2: 0.99

# Loss weights
gp_weight: 10
adv_weight: 1e-5

# Training
batch_size: 9
num_epochs: 100
psnr_gain_tol: 0.25

num_workers: 4
3 changes: 3 additions & 0 deletions configs/mri.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ checkpoint_dir: "/share/gpu0/tl3/MRI/mri_models/"
data_path: "/share/gpu0/tl3/fastMRI_dataset"
sense_maps_path: "/share/gpu0/tl3/MRI/sense_maps/"

# Define the experience
experience: mri

# MRI Args
num_of_top_slices: 8
use-middle-slices: false
Expand Down
34 changes: 34 additions & 0 deletions configs/radio_fourier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#Change checkpoint and sense_map path
checkpoint_dir: /share/gpu0/mars/TNG_data/rcGAN/models/
data_path: /share/gpu0/mars/TNG_data/rcGAN/fourier/

# Define the experience
experience: radio

# Number of code vectors for each phase
num_z_test: 32
num_z_valid: 8
num_z_train: 2

# Data
in_chans: 3 # Real+Imag parts from obs
out_chans: 2
im_size: 360 #384x384 pixel images


# Optimizer:
lr: 0.001
beta_1: 0
beta_2: 0.99

# Loss weights
gp_weight: 10
adv_weight: 1e-5

# Training
batch_size: 1
#Remember to increase this for full training
num_epochs: 10
psnr_gain_tol: 0.25

num_workers: 4
34 changes: 34 additions & 0 deletions configs/radio_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#Change checkpoint and sense_map path
checkpoint_dir: /share/gpu0/mars/TNG_data/rcGAN/models/varying/
data_path: /share/gpu0/mars/TNG_data/rcGAN/image_psfs/

# Define the experience
experience: radio

# Number of code vectors for each phase
num_z_test: 32
num_z_valid: 8
num_z_train: 2

# Data
in_chans: 3 # Real+Imag parts from obs
out_chans: 2
im_size: 256 #384x384 pixel images


# Optimizer:
lr: 0.001
beta_1: 0
beta_2: 0.99

# Loss weights
gp_weight: 10
adv_weight: 1e-5

# Training
batch_size: 8
#Remember to increase this for full training
num_epochs: 100
psnr_gain_tol: 0.25

num_workers: 4
35 changes: 35 additions & 0 deletions configs/radio_image_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#Change checkpoint and sense_map path
checkpoint_dir: /share/gpu0/tl3/cGAN/radio/trained_model/
data_path: /share/gpu0/mars/TNG_data/rcGAN/image_psfs/

# Define the experience
experience: radio

# Number of code vectors for each phase
num_z_test: 32
num_z_valid: 8
num_z_train: 2

# Data
in_chans: 3 # Real+Imag parts from obs
out_chans: 2
im_size: 256 #384x384 pixel images


# Optimizer:
lr: 0.001
beta_1: 0
beta_2: 0.99

# Loss weights
gp_weight: 10
adv_weight: 1e-5

# Training
batch_size: 4
accumulate_grad_batches: 2
#Remember to increase this for full training
num_epochs: 1
psnr_gain_tol: 0.25

num_workers: 1
Loading