X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=pytorch.git;a=blobdiff_plain;f=hallu.py;h=de251884c8c8bafac1e307030ccce1f61ee1935e;hp=6b0b303ec503472b81818e43a5347ce9d35cc318;hb=d74d7be5abef26c78d014bd179f2c52f81aca65b;hpb=e111e52ea09f03fc309052b00a452ced52668f70 diff --git a/hallu.py b/hallu.py index 6b0b303..de25188 100755 --- a/hallu.py +++ b/hallu.py @@ -1,5 +1,10 @@ #!/usr/bin/env python +# Any copyright is dedicated to the Public Domain. +# https://creativecommons.org/publicdomain/zero/1.0/ + +# Written by Francois Fleuret + # ImageMagick's montage to make the mosaic # # montage hallu-*.png -tile 5x6 -geometry +1+1 result.png @@ -9,10 +14,10 @@ from torch.nn import functional as F class MultiScaleEdgeEnergy(torch.nn.Module): def __init__(self): - super(MultiScaleEdgeEnergy, self).__init__() + super().__init__() k = torch.exp(- torch.tensor([[-2., -1., 0., 1., 2.]])**2 / 2) k = (k.t() @ k).view(1, 1, 5, 5) - self.register_buffer('gaussian_5x5', k / k.sum()) + self.gaussian_5x5 = torch.nn.Parameter(k / k.sum()).requires_grad_(False) def forward(self, x): u = x.view(-1, 1, x.size(2), x.size(3)) @@ -43,7 +48,7 @@ for l in [ 5, 7, 12, 17, 21, 28 ]: ref_output = model(ref_input).detach() for n in range(5): - input = ref_input.new_empty(ref_input.size()).uniform_(-0.01, 0.01).requires_grad_() + input = torch.empty_like(ref_input).uniform_(-0.01, 0.01).requires_grad_() optimizer = torch.optim.Adam( [ input ], lr = 1e-2) for k in range(1000): output = model(input)