Skip to content

Commit ad3335b

Browse files
committed
Use per-img noises in projector.py
1 parent 45c06c4 commit ad3335b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

‎projector.py‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def noise_regularize(noises):
2929
if size <= 8:
3030
break
3131

32-
noise = noise.reshape([1, 1, size // 2, 2, size // 2, 2])
32+
noise = noise.reshape([-1, 1, size // 2, 2, size // 2, 2])
3333
noise = noise.mean([3, 5])
3434
size //= 2
3535

@@ -128,7 +128,10 @@ def make_image(tensor):
128128
model="net-lin", net="vgg", use_gpu=device.startswith("cuda")
129129
)
130130

131-
noises = g_ema.make_noise()
131+
noises_single = g_ema.make_noise()
132+
noises = []
133+
for noise in noises_single:
134+
noises.append(noise.repeat(imgs.shape[0], 1, 1, 1).normal_())
132135

133136
latent_in = latent_mean.detach().clone().unsqueeze(0).repeat(imgs.shape[0], 1)
134137

@@ -186,16 +189,24 @@ def make_image(tensor):
186189
)
187190
)
188191

189-
result_file = {"noises": noises}
190-
191192
img_gen, _ = g_ema([latent_path[-1]], input_is_latent=True, noise=noises)
192193

193194
filename = os.path.splitext(os.path.basename(args.files[0]))[0] + ".pt"
194195

195196
img_ar = make_image(img_gen)
196197

198+
result_file = {}
197199
for i, input_name in enumerate(args.files):
198-
result_file[input_name] = {"img": img_gen[i], "latent": latent_in[i]}
200+
noise_single = []
201+
for noise in noises:
202+
noise_single.append(noise[i : i + 1])
203+
204+
result_file[input_name] = {
205+
"img": img_gen[i],
206+
"latent": latent_in[i],
207+
"noise": noise_single,
208+
}
209+
199210
img_name = os.path.splitext(os.path.basename(input_name))[0] + "-project.png"
200211
pil_img = Image.fromarray(img_ar[i])
201212
pil_img.save(img_name)

0 commit comments

Comments
 (0)