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)
| 181 | |
| 182 | |
| 183 | def 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 | |
| 219 | def reshape_local_connection_2d_weights( |
no outgoing calls
no test coverage detected