-
Notifications
You must be signed in to change notification settings - Fork 11
weak lensing encoder shear updates #1072
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
213b35c
Refactor generate_cached_data in lensing_dc2
timwhite0 8e4f0ec
Decrease learning rate, remove clamp on convergence stdev
timwhite0 573e220
Remove some print statements in lensing_encoder
timwhite0 f7e917c
in progress changes to normalizer, convnet, and encoder, as well as m…
b00915f
Merge branch 'tw/weak_lensing' of github.com:prob-ml/bliss into sc/we…
shreyasc30 12b96ea
new architecture with resnet and resnetx layers as well as prelim cha…
shreyasc30 6fca37c
Merge branch 'master' of github.com:prob-ml/bliss into sc/weak_lensin…
shreyasc30 3e4260c
updated to make shear1 and shear2 separate normal factors
shreyasc30 a727073
updated lensing config to split up shear_1 and shear_2 as nf
b471c55
updated network due to OOM
a3901fd
removed print statements from enc
51b66ea
Merge branch 'master' of github.com:prob-ml/bliss into sc/weak_lensin…
48a4e7e
rolled back some debug changes and re-established consistency with ma…
f77dc45
deduped lensing config
shreyasc30 93dcdbe
styling tests
shreyasc30 5e6f535
style checks update
shreyasc30 0ffa312
removed try/catch from cached_datset and made fix to lensing_dc2
shreyasc30 0049b4d
fixed lensing MSE denominator
shreyasc30 a13010c
fixed lensing config
shreyasc30 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import math | ||
|
||
from torch import nn | ||
|
||
|
||
class RN2Block(nn.Module): | ||
def __init__(self, in_channels, out_channels, stride=1): | ||
super().__init__() | ||
self.conv1 = nn.Conv2d( | ||
in_channels, out_channels, kernel_size=3, stride=stride, padding=1, bias=False | ||
) | ||
out_c_sqrt = math.sqrt(out_channels) | ||
if out_c_sqrt.is_integer(): | ||
n_groups = int(out_c_sqrt) | ||
else: | ||
n_groups = int( | ||
math.sqrt(out_channels * 2) | ||
) # even powers of 2 guaranteed to be perfect squares | ||
self.gn1 = nn.GroupNorm(num_groups=n_groups, num_channels=out_channels) | ||
self.silu = nn.SiLU(inplace=True) | ||
self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1, bias=False) | ||
self.gn2 = nn.GroupNorm(num_groups=n_groups, num_channels=out_channels) | ||
self.downsample = None | ||
if stride != 1 or in_channels != out_channels: | ||
self.downsample = nn.Sequential( | ||
nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=stride, bias=False), | ||
nn.GroupNorm(num_groups=n_groups, num_channels=out_channels), | ||
) | ||
|
||
def forward(self, x): | ||
identity = x | ||
|
||
out = self.conv1(x) | ||
out = self.gn1(out) | ||
out = self.silu(out) | ||
|
||
out = self.conv2(out) | ||
out = self.gn2(out) | ||
|
||
if self.downsample: | ||
identity = self.downsample(x) | ||
|
||
out += identity | ||
out = self.silu(out) | ||
|
||
return out # noqa: WPS331 | ||
|
||
|
||
class ResNeXtBlock(nn.Module): | ||
def __init__(self, in_channels, mid_channels, out_channels, stride=1, groups=32): | ||
super().__init__() | ||
self.conv1 = nn.Conv2d(in_channels, mid_channels, kernel_size=1, stride=1, padding=0) | ||
mid_c_sqrt = math.sqrt(mid_channels) | ||
if mid_c_sqrt.is_integer(): | ||
mid_norm_n_groups = int(mid_c_sqrt) | ||
else: | ||
mid_norm_n_groups = int( | ||
math.sqrt(mid_channels * 2) | ||
) # even powers of 2 guaranteed to be perfect squares | ||
self.gn1 = nn.GroupNorm(num_groups=mid_norm_n_groups, num_channels=mid_channels) | ||
self.conv2 = nn.Conv2d( | ||
mid_channels, mid_channels, kernel_size=3, stride=stride, padding=1, groups=groups | ||
) | ||
self.gn2 = nn.GroupNorm(num_groups=mid_norm_n_groups, num_channels=mid_channels) | ||
self.conv3 = nn.Conv2d(mid_channels, out_channels, kernel_size=1, stride=1, padding=0) | ||
out_c_sqrt = math.sqrt(out_channels) | ||
if out_c_sqrt.is_integer(): | ||
out_norm_n_groups = int(out_c_sqrt) | ||
else: | ||
out_norm_n_groups = int( | ||
math.sqrt(out_channels * 2) | ||
) # even powers of 2 guaranteed to be perfect squares | ||
self.gn3 = nn.GroupNorm(num_groups=out_norm_n_groups, num_channels=out_channels) | ||
self.silu = nn.SiLU(inplace=True) | ||
|
||
# Adjust the shortcut connection to match the output dimensions | ||
self.shortcut = None | ||
if stride != 1 or in_channels != out_channels: | ||
self.shortcut = nn.Sequential( | ||
nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=stride, padding=0), | ||
nn.GroupNorm(out_channels), | ||
) | ||
|
||
def forward(self, x): | ||
residual = x | ||
out = self.conv1(x) | ||
out = self.gn1(out) | ||
out = self.silu(out) | ||
out = self.conv2(out) | ||
out = self.gn2(out) | ||
out = self.silu(out) | ||
out = self.conv3(out) | ||
out = self.gn3(out) | ||
if self.shortcut: | ||
residual = self.shortcut(x) | ||
out += residual | ||
out = self.silu(out) | ||
return out # noqa: WPS331 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.