Skip to content

Commit 138c5dc

Browse files
authored
Check if 'cnn_output_size' is zero in CNNembedding. (#1281)
* cnn output size check * minor corrections * fixed linting * variability for 1D conv * use more consize all * ruff check again
1 parent 1d4ee7a commit 138c5dc

File tree

1 file changed

+7
-0
lines changed
  • sbi/neural_nets/embedding_nets

1 file changed

+7
-0
lines changed

sbi/neural_nets/embedding_nets/cnn.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def __init__(
127127
cnn_output_size = input_shape
128128
stride = 1
129129
padding = 1
130+
130131
for ii in range(num_conv_layers):
131132
# Defining another 2D convolution layer
132133
conv_layer = conv_module(
@@ -141,6 +142,12 @@ def __init__(
141142
# Calculate change of output size of each CNN layer
142143
cnn_output_size = get_new_cnn_output_size(cnn_output_size, conv_layer, pool)
143144

145+
assert all(
146+
cnn_output_size
147+
), f"""CNN output size is zero at layer {ii + 1}. Either reduce
148+
num_cnn_layers to {ii} or adjust the kernel_size
149+
and pool_kernel_size accordingly."""
150+
144151
self.cnn_subnet = nn.Sequential(*cnn_layers)
145152

146153
# Construct linear post processing net.

0 commit comments

Comments
 (0)