This commit is contained in:
zhangmozhe
2020-12-01 14:06:29 +08:00
parent 5118d07b0f
commit 0c1389853a
246 changed files with 186 additions and 3834 deletions
+1 -5
View File
@@ -1,9 +1,6 @@
import torch
import torch.nn.functional as F
from torch import Tensor, nn
from torch.autograd import Variable
from torch import nn
from torch.nn import Parameter
from torch.optim.optimizer import Optimizer, required
def l2normalize(v, eps=1e-12):
@@ -29,7 +26,6 @@ class SpectralNorm(nn.Module):
v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data))
u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data))
# sigma = torch.dot(u.data, torch.mv(w.view(height,-1).data, v.data))
sigma = u.dot(w.view(height, -1).mv(v))
setattr(self.module, self.name, w / sigma.expand_as(w))