Skip to content

Commit 4b143a4

Browse files
author
rbodo
committed
Fixed weight name parser for depthwise-separable convolutions. Fixed activity plots for 1D convolutions.
1 parent c792a46 commit 4b143a4

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

snntoolbox/parsing/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@ def layers_to_skip(self):
393393
'Activation',
394394
'Dropout',
395395
'ReLU',
396-
'ActivityRegularization']
396+
'ActivityRegularization',
397+
'GaussianNoise']
397398

398399
@abstractmethod
399400
def has_weights(self, layer):

snntoolbox/simulation/plotting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,8 +1154,8 @@ def plot_input_image(x, label, path=None, data_format=None, filename=None):
11541154
if data_format == 'channels_first':
11551155
x = np.transpose(x, (1, 2, 0))
11561156

1157-
if x.shape[-1] == 1 and x.ndim > 2:
1158-
x = x[..., 0]
1157+
if x.ndim > 2:
1158+
x = np.squeeze(x)
11591159

11601160
plt.figure()
11611161
plt.title('Input image (class: {})'.format(label))

snntoolbox/simulation/target_simulators/INI_temporal_mean_rate_target_sim.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from __future__ import print_function, unicode_literals
99

1010
import os
11-
import re
1211
import sys
1312

1413
import keras
@@ -114,11 +113,22 @@ def compile(self):
114113
# Need to extract the actual weights here.
115114

116115
def remove_name_counter(name_in):
117-
splits = str(name_in).split('_')
118-
name_out = splits[0] + '_' + splits[1]
119-
if len(splits) == 3:
120-
name_out += re.sub(r'\d+/', '/', splits[2])
121-
return name_out
116+
"""
117+
Tensorflow adds a counter to layer names, e.g. <name>/kernel:0 ->
118+
<name>_0/kernel:0. Need to remove this _0.
119+
Situation get complicated because SNN toolbox assigns layer names
120+
that contain the layer shape, e.g. 00Conv2D_3x32x32. In addition,
121+
we may get another underscore in the parameter name, e.g.
122+
00DepthwiseConv2D_3X32x32_0/depthwise_kernel:0.
123+
"""
124+
125+
split_dash = str(name_in).split('/')
126+
assert len(split_dash) == 2, "Layer name must not contain '/'."
127+
# We are only interested in the part before the /.
128+
split_underscore = split_dash[0].split('_')
129+
# The first '_' is assigned by SNN toolbox and should be kept.
130+
return (split_underscore[0] + '_' + split_underscore[1] + '/' +
131+
split_dash[1])
122132

123133
parameter_map = {remove_name_counter(p.name): v for p, v in
124134
zip(self.parsed_model.weights,

0 commit comments

Comments
 (0)