|
| 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).
|
|
Linear layer with spectral norm
Definition at line 347 of file ieagan.py.
◆ __init__()
__init__ |
( |
| self, |
|
|
| in_features, |
|
|
| out_features, |
|
|
| bias = True, |
|
|
| num_svs = 1, |
|
|
| num_itrs = 1, |
|
|
| eps = 1e-12 ) |
Constructor.
Definition at line 353 of file ieagan.py.
361 ):
362 nn.Linear.__init__(self, in_features, out_features, bias)
363 SN.__init__(self, num_svs, num_itrs, out_features, eps=eps)
364
◆ forward()
forward
Definition at line 366 of file ieagan.py.
366 def forward(self, x):
367
368 return F.linear(x, self.W_(), self.bias)
369
370
371
◆ 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