Skip to content

Commit b70a882

Browse files
committed
core: pass strict_layer_type arg to cortical sheet op
1 parent 29798e0 commit b70a882

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

topoloss/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def get_layerwise_topo_losses(self, model, do_scaling: bool = True) -> dict:
3939

4040
if isinstance(loss_info, LaplacianPyramid):
4141
if isinstance(layer, nn.Linear):
42-
cortical_sheet = get_cortical_sheet_linear(layer=layer)
42+
cortical_sheet = get_cortical_sheet_linear(layer=layer, strict_layer_type=self.strict_layer_type)
4343
else:
44-
cortical_sheet = get_cortical_sheet_conv(layer=layer)
44+
cortical_sheet = get_cortical_sheet_conv(layer=layer, strict_layer_type=self.strict_layer_type)
4545

4646
loss = laplacian_pyramid_loss(
4747
cortical_sheet=cortical_sheet,

topoloss/cortical_sheet/input.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from .common import find_cortical_sheet_size, GridDimensions2D
44

55

6-
def get_cortical_sheet_linear_input(layer: nn.Linear):
7-
assert isinstance(layer, nn.Linear)
6+
def get_cortical_sheet_linear_input(layer: nn.Linear, strict_layer_type: bool = True):
7+
if strict_layer_type is True:
8+
assert isinstance(layer, nn.Linear)
89
weight = layer.weight
910
num_input_neurons = weight.shape[1]
1011
assert weight.ndim == 2

topoloss/cortical_sheet/output.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from .common import find_cortical_sheet_size, GridDimensions2D
44

55

6-
def get_cortical_sheet_linear(layer: nn.Linear):
7-
assert isinstance(layer, nn.Linear)
6+
def get_cortical_sheet_linear(layer: nn.Linear, strict_layer_type: bool):
7+
if strict_layer_type is True:
8+
assert isinstance(layer, nn.Linear)
89
weight = layer.weight
910
num_output_neurons = weight.shape[0]
1011
assert weight.ndim == 2
@@ -16,8 +17,9 @@ def get_cortical_sheet_linear(layer: nn.Linear):
1617
)
1718

1819

19-
def get_cortical_sheet_conv(layer: nn.Conv2d):
20-
assert isinstance(layer, nn.Conv2d)
20+
def get_cortical_sheet_conv(layer: nn.Conv2d, strict_layer_type: bool):
21+
if strict_layer_type is True:
22+
assert isinstance(layer, nn.Conv2d)
2123
weight = layer.weight
2224
assert weight.ndim == 4
2325
num_output_channels = weight.shape[0]

0 commit comments

Comments
 (0)