Spaces:
Running
on
A10G
Running
on
A10G
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ def get_pattern(shape, w_seed=999999):
|
|
| 31 |
g = torch.Generator(device=pipe.device)
|
| 32 |
g.manual_seed(w_seed)
|
| 33 |
gt_init = pipe.prepare_latents(1, pipe.unet.in_channels,
|
| 34 |
-
|
| 35 |
pipe.unet.dtype, pipe.device, g)
|
| 36 |
gt_patch = torch.fft.fftshift(torch.fft.fft2(gt_init), dim=(-1, -2))
|
| 37 |
# ring pattern. paper found this to be effective
|
|
@@ -45,7 +45,7 @@ def get_pattern(shape, w_seed=999999):
|
|
| 45 |
return gt_patch
|
| 46 |
|
| 47 |
def transform_img(image):
|
| 48 |
-
tform = tforms.Compose([tforms.Resize(
|
| 49 |
image = tform(image)
|
| 50 |
return 2.0 * image - 1.0
|
| 51 |
|
|
@@ -68,7 +68,7 @@ def get_noise():
|
|
| 68 |
|
| 69 |
# inject watermark
|
| 70 |
init_latents = pipe.prepare_latents(1, pipe.unet.in_channels,
|
| 71 |
-
|
| 72 |
pipe.unet.dtype, pipe.device, None)
|
| 73 |
init_latents_fft = torch.fft.fftshift(torch.fft.fft2(init_latents), dim=(-1, -2))
|
| 74 |
init_latents_fft[w_mask] = w_key[w_mask].clone()
|
|
@@ -86,7 +86,7 @@ def detect(image):
|
|
| 86 |
|
| 87 |
# ddim inversion
|
| 88 |
img = transform_img(image).unsqueeze(0).to(pipe.unet.dtype).to(pipe.device)
|
| 89 |
-
image_latents = pipe.vae.encode(img).latent_dist.mode() * 0.
|
| 90 |
inverted_latents = pipe(prompt="", latents=image_latents, guidance_scale=1, num_inference_steps=50, output_type="latent")
|
| 91 |
inverted_latents = inverted_latents.images
|
| 92 |
|
|
|
|
| 31 |
g = torch.Generator(device=pipe.device)
|
| 32 |
g.manual_seed(w_seed)
|
| 33 |
gt_init = pipe.prepare_latents(1, pipe.unet.in_channels,
|
| 34 |
+
512, 512,
|
| 35 |
pipe.unet.dtype, pipe.device, g)
|
| 36 |
gt_patch = torch.fft.fftshift(torch.fft.fft2(gt_init), dim=(-1, -2))
|
| 37 |
# ring pattern. paper found this to be effective
|
|
|
|
| 45 |
return gt_patch
|
| 46 |
|
| 47 |
def transform_img(image):
|
| 48 |
+
tform = tforms.Compose([tforms.Resize(512),tforms.CenterCrop(512),tforms.ToTensor()])
|
| 49 |
image = tform(image)
|
| 50 |
return 2.0 * image - 1.0
|
| 51 |
|
|
|
|
| 68 |
|
| 69 |
# inject watermark
|
| 70 |
init_latents = pipe.prepare_latents(1, pipe.unet.in_channels,
|
| 71 |
+
512, 512,
|
| 72 |
pipe.unet.dtype, pipe.device, None)
|
| 73 |
init_latents_fft = torch.fft.fftshift(torch.fft.fft2(init_latents), dim=(-1, -2))
|
| 74 |
init_latents_fft[w_mask] = w_key[w_mask].clone()
|
|
|
|
| 86 |
|
| 87 |
# ddim inversion
|
| 88 |
img = transform_img(image).unsqueeze(0).to(pipe.unet.dtype).to(pipe.device)
|
| 89 |
+
image_latents = pipe.vae.encode(img).latent_dist.mode() * 0.18215
|
| 90 |
inverted_latents = pipe(prompt="", latents=image_latents, guidance_scale=1, num_inference_steps=50, output_type="latent")
|
| 91 |
inverted_latents = inverted_latents.images
|
| 92 |
|