RamAnanth1 commited on
Commit
b92c307
1 Parent(s): af3e036

Update app.py

Browse files

Fix indent error

Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -107,26 +107,26 @@ def process_image_inpaint(raw_image,mask, prompt):
107
  target_image = target_image.resize((512, 512))
108
 
109
  with torch.autocast('cuda'):
110
- mask, X = prepare_mask_and_masked_image(init_image, mask_image)
111
- X = X.half().cuda()
112
- mask = mask.half().cuda()
 
 
 
113
 
114
- # Here we attack towards the embedding of a random target image. You can also simply attack towards an embedding of zeros!
115
- target = pipe_inpaint.vae.encode(preprocess(target_image).half().cuda()).latent_dist.mean
116
-
117
- adv_X = pgd(X,
118
- target = target,
119
- model=pipe_inpaint.vae.encode,
120
- criterion=torch.nn.MSELoss(),
121
- clamp_min=-1,
122
- clamp_max=1,
123
- eps=0.06,
124
- step_size=0.01,
125
- iters=1000,
126
- mask=1-mask
127
- )
128
-
129
- adv_X = (adv_X / 2 + 0.5).clamp(0, 1)
130
 
131
  adv_image = to_pil(adv_X[0]).convert("RGB")
132
  adv_image = recover_image(adv_image, init_image, mask_image, background=True)
 
107
  target_image = target_image.resize((512, 512))
108
 
109
  with torch.autocast('cuda'):
110
+ mask, X = prepare_mask_and_masked_image(init_image, mask_image)
111
+ X = X.half().cuda()
112
+ mask = mask.half().cuda()
113
+
114
+ # Here we attack towards the embedding of a random target image. You can also simply attack towards an embedding of zeros!
115
+ target = pipe_inpaint.vae.encode(preprocess(target_image).half().cuda()).latent_dist.mean
116
 
117
+ adv_X = pgd(X,
118
+ target = target,
119
+ model=pipe_inpaint.vae.encode,
120
+ criterion=torch.nn.MSELoss(),
121
+ clamp_min=-1,
122
+ clamp_max=1,
123
+ eps=0.06,
124
+ step_size=0.01,
125
+ iters=1000,
126
+ mask=1-mask
127
+ )
128
+
129
+ adv_X = (adv_X / 2 + 0.5).clamp(0, 1)
 
 
 
130
 
131
  adv_image = to_pil(adv_X[0]).convert("RGB")
132
  adv_image = recover_image(adv_image, init_image, mask_image, background=True)