|
| bias |
|
| 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.
|
|
| training |
|
Linear layer with spectral norm
Definition at line 330 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 336 of file ieagan.py.
344 ):
345 nn.Linear.__init__(self, in_features, out_features, bias)
346 SN.__init__(self, num_svs, num_itrs, out_features, eps=eps)
347
◆ forward()
forward
Definition at line 349 of file ieagan.py.
349 def forward(self, x):
350 return F.linear(x, self.W_(), self.bias)
351
352
◆ sv()
Singular values
note that these buffers are just for logging and are not used in training.
Definition at line 256 of file ieagan.py.
256 def sv(self):
257 """
258 Singular values
259 note that these buffers are just for logging and are not used in training.
260 """
261 return [getattr(self, f"sv{i:d}") for i in range(self.num_svs)]
262
◆ u()
Singular vectors (u side)
Definition at line 249 of file ieagan.py.
249 def u(self):
250 """
251 Singular vectors (u side)
252 """
253 return [getattr(self, f"u{i:d}") for i in range(self.num_svs)]
254
◆ W_()
Compute the spectrally-normalized weight
Definition at line 263 of file ieagan.py.
263 def W_(self):
264 """
265 Compute the spectrally-normalized weight
266 """
267 W_mat = self.weight.view(self.weight.size(0), -1)
268 if self.transpose:
269 W_mat = W_mat.t()
270
271 for _ in range(self.num_itrs):
272 svs, _, _ = power_iteration(
273 W_mat, self.u, update=self.training, eps=self.eps
274 )
275
276 if self.training:
277
278 with torch.no_grad():
279 for i, sv in enumerate(svs):
280 self.sv[i][:] = sv
281 return self.weight / svs[0]
282
283
◆ bias
◆ eps
Epsilon value for avoiding divide-by-0.
Definition at line 242 of file ieagan.py.
◆ num_itrs
Number of power iterations per step.
Definition at line 236 of file ieagan.py.
◆ num_svs
Number of singular values.
Definition at line 238 of file ieagan.py.
◆ training
Initial value:= power_iteration(
W_mat, self.u, update=self.training, eps=self.eps
)
Definition at line 276 of file ieagan.py.
◆ transpose
The documentation for this class was generated from the following file:
- pxd/scripts/pxd/background_generator/models/ieagan.py