MCPcopy Create free account
hub / github.com/BindsNET/bindsnet / reshape_conv2d_weights

Function reshape_conv2d_weights

bindsnet/utils.py:183–216  ·  view source on GitHub ↗

Flattens a connection weight matrix of a Conv2dConnection :param weights: Weight matrix of Conv2dConnection object. :param wmin: Minimum allowed weight value. :param wmax: Maximum allowed weight value.

(weights: torch.Tensor)

Source from the content-addressed store, hash-verified

181
182
183def reshape_conv2d_weights(weights: torch.Tensor) -> torch.Tensor:
184 # language=rst
185 """
186 Flattens a connection weight matrix of a Conv2dConnection
187
188 :param weights: Weight matrix of Conv2dConnection object.
189 :param wmin: Minimum allowed weight value.
190 :param wmax: Maximum allowed weight value.
191 """
192 sqrt1 = int(np.ceil(np.sqrt(weights.size(0))))
193 sqrt2 = int(np.ceil(np.sqrt(weights.size(1))))
194 height, width = weights.size(2), weights.size(3)
195 reshaped = torch.zeros(
196 sqrt1 * sqrt2 * weights.size(2), sqrt1 * sqrt2 * weights.size(3)
197 )
198
199 for i in range(sqrt1):
200 for j in range(sqrt1):
201 for k in range(sqrt2):
202 for l in range(sqrt2):
203 if i * sqrt1 + j < weights.size(0) and k * sqrt2 + l < weights.size(
204 1
205 ):
206 fltr = weights[i * sqrt1 + j, k * sqrt2 + l].view(height, width)
207 reshaped[
208 i * height
209 + k * height * sqrt1 : (i + 1) * height
210 + k * height * sqrt1,
211 (j % sqrt1) * width
212 + (l % sqrt2) * width * sqrt1 : ((j % sqrt1) + 1) * width
213 + (l % sqrt2) * width * sqrt1,
214 ] = fltr
215
216 return reshaped
217
218
219def reshape_local_connection_2d_weights(

Callers 2

plot_conv2d_weightsFunction · 0.90
plot_conv2d_weightsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected