|
| __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) |
|
2D Conv layer with spectral norm
Definition at line 284 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 290 of file ieagan.py.
303 ):
304 nn.Conv2d.__init__(
305 self,
306 in_channels,
307 out_channels,
308 kernel_size,
309 stride,
310 padding,
311 dilation,
312 groups,
313 bias,
314 )
315 SN.__init__(self, num_svs, num_itrs, out_channels, eps=eps)
316
◆ forward()
forward
Definition at line 318 of file ieagan.py.
318 def forward(self, x):
319 return F.conv2d(
320 x,
321 self.W_(),
322 self.bias,
323 self.stride,
324 self.padding,
325 self.dilation,
326 self.groups,
327 )
328
329
◆ 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
◆ dilation
◆ eps
Epsilon value for avoiding divide-by-0.
Definition at line 242 of file ieagan.py.
◆ groups
◆ 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.
◆ padding
◆ stride
◆ 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