forked from ML4GW/amplfi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add function to return time and frequency domain waveforms * add multimodal resnet * switch from fft to rfft * run pre-commit * add docstring * add prefix freq for frequency domain waveforms * update docstring, add args for time and freq separately * switch to relative import * add test for multimodal embedding * pass patience correctly through the scheduler * remove asds from datamodule.inject output * hardcode patience=20 * remove patience as a class variable * remove asds * add scheduler patience and factor as arguments of the model * remove time_and_frequency_domain_strain
- Loading branch information
1 parent
7014809
commit 4d9319c
Showing
8 changed files
with
116 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .dense import CoherentDenseEmbedding, NChannelDenseEmbedding | ||
from .flattener import Flattener | ||
from .multimodal import MultiModal | ||
from .resnet import ResNet |
This file contains 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,70 @@ | ||
from typing import Literal, Optional | ||
|
||
import torch | ||
from ml4gw.nn.norm import NormLayer | ||
from ml4gw.nn.resnet.resnet_1d import ResNet1D | ||
|
||
from .base import Embedding | ||
|
||
|
||
class MultiModal(Embedding): | ||
def __init__( | ||
self, | ||
num_ifos: int, | ||
time_context_dim: int, | ||
freq_context_dim: int, | ||
time_layers: list[int], | ||
freq_layers: list[int], | ||
time_kernel_size: int = 3, | ||
freq_kernel_size: int = 3, | ||
zero_init_residual: bool = False, | ||
groups: int = 1, | ||
width_per_group: int = 64, | ||
stride_type: Optional[list[Literal["stride", "dilation"]]] = None, | ||
norm_layer: Optional[NormLayer] = None, | ||
**kwargs | ||
): | ||
""" | ||
MultiModal embedding network that embeds both time and frequency data. | ||
We pass the data through their own ResNets defined by their layers | ||
and context dims, then concatenate the output embeddings. | ||
""" | ||
super().__init__() | ||
self.time_domain_resnet = ResNet1D( | ||
in_channels=num_ifos, | ||
layers=time_layers, | ||
classes=time_context_dim, | ||
kernel_size=time_kernel_size, | ||
zero_init_residual=zero_init_residual, | ||
groups=groups, | ||
width_per_group=width_per_group, | ||
stride_type=stride_type, | ||
norm_layer=norm_layer, | ||
) | ||
self.frequency_domain_resnet = ResNet1D( | ||
in_channels=int(num_ifos * 2), | ||
layers=freq_layers, | ||
classes=freq_context_dim, | ||
kernel_size=freq_kernel_size, | ||
zero_init_residual=zero_init_residual, | ||
groups=groups, | ||
width_per_group=width_per_group, | ||
stride_type=stride_type, | ||
norm_layer=norm_layer, | ||
) | ||
|
||
# set the context dimension so | ||
# the flow can access it | ||
self.context_dim = time_context_dim + freq_context_dim | ||
|
||
def forward(self, X): | ||
time_domain_embedded = self.time_domain_resnet(X) | ||
X_fft = torch.fft.rfft(X) | ||
X_fft = torch.cat((X_fft.real, X_fft.imag), dim=1) | ||
frequency_domain_embedded = self.frequency_domain_resnet(X_fft) | ||
|
||
embedding = torch.concat( | ||
(time_domain_embedded, frequency_domain_embedded), dim=1 | ||
) | ||
return embedding |
This file contains 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 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 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 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 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 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