|
| __init__ (self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, num_svs=1, num_itrs=1, eps=1e-12) |
| Constructor.
|
|
| forward (self, x) |
| forward
|
|
| u (self) |
|
| sv (self) |
|
| W_ (self) |
|
|
| num_itrs = num_itrs |
| Number of power iterations per step.
|
|
| num_svs = num_svs |
| Number of singular values.
|
|
| transpose = transpose |
| Transposed?
|
|
| eps = eps |
| Epsilon value for avoiding divide-by-0.
|
|
bool | training |
| Training mode flag (inherited from nn.Module).
|
|
2D Conv layer with spectral norm
Definition at line 299 of file ieagan.py.
◆ __init__()
__init__ |
( |
| self, |
|
|
| in_channels, |
|
|
| out_channels, |
|
|
| kernel_size, |
|
|
| stride = 1, |
|
|
| padding = 0, |
|
|
| dilation = 1, |
|
|
| groups = 1, |
|
|
| bias = True, |
|
|
| num_svs = 1, |
|
|
| num_itrs = 1, |
|
|
| eps = 1e-12 ) |
Constructor.
Definition at line 305 of file ieagan.py.
318 ):
319 nn.Conv2d.__init__(
320 self,
321 in_channels,
322 out_channels,
323 kernel_size,
324 stride,
325 padding,
326 dilation,
327 groups,
328 bias,
329 )
330 SN.__init__(self, num_svs, num_itrs, out_channels, eps=eps)
331
◆ forward()
forward
Definition at line 333 of file ieagan.py.
333 def forward(self, x):
334 return F.conv2d(
335 x,
336 self.W_(),
337
338 self.bias,
339 self.stride,
340 self.padding,
341 self.dilation,
342 self.groups,
343
344 )
345
346
◆ sv()
Singular values
note that these buffers are just for logging and are not used in training.
Definition at line 271 of file ieagan.py.
271 def sv(self):
272 """
273 Singular values
274 note that these buffers are just for logging and are not used in training.
275 """
276 return [getattr(self, f"sv{i:d}") for i in range(self.num_svs)]
277
◆ u()
Singular vectors (u side)
Definition at line 264 of file ieagan.py.
264 def u(self):
265 """
266 Singular vectors (u side)
267 """
268 return [getattr(self, f"u{i:d}") for i in range(self.num_svs)]
269
◆ W_()
Compute the spectrally-normalized weight
Definition at line 278 of file ieagan.py.
278 def W_(self):
279 """
280 Compute the spectrally-normalized weight
281 """
282 W_mat = self.weight.view(self.weight.size(0), -1)
283 if self.transpose:
284 W_mat = W_mat.t()
285
286 for _ in range(self.num_itrs):
287 svs, _, _ = power_iteration(
288 W_mat, self.u, update=self.training, eps=self.eps
289 )
290
291 if self.training:
292
293 with torch.no_grad():
294 for i, sv in enumerate(svs):
295 self.sv[i][:] = sv
296 return self.weight / svs[0]
297
298
◆ eps
Epsilon value for avoiding divide-by-0.
Definition at line 255 of file ieagan.py.
◆ num_itrs
Number of power iterations per step.
Definition at line 249 of file ieagan.py.
◆ num_svs
Number of singular values.
Definition at line 251 of file ieagan.py.
◆ training
Training mode flag (inherited from nn.Module).
True if the module is in training mode.
Definition at line 261 of file ieagan.py.
◆ transpose
The documentation for this class was generated from the following file:
- pxd/scripts/pxd/background_generator/models/ieagan.py