josuelmet commited on
Commit
78aed89
·
1 Parent(s): eb07fe2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -6,6 +6,11 @@ from torchvision import transforms as T
6
 
7
  from boomerang import *
8
 
 
 
 
 
 
9
  def main(image, prompt, percent_noise): # percent_noise = 0.5, 0.02, 0.999
10
 
11
  # Convert image to float and preprocess it.
@@ -14,7 +19,10 @@ def main(image, prompt, percent_noise): # percent_noise = 0.5, 0.02, 0.999
14
  T.ConvertImageDtype(torch.float),
15
  T.Normalize([0.5], [0.5])])
16
 
17
- tensor = transform(image).half().to(pipe.device)
 
 
 
18
  tensor = torch.unsqueeze(tensor, 0)
19
 
20
  # Project image into the latent space
@@ -25,7 +33,9 @@ def main(image, prompt, percent_noise): # percent_noise = 0.5, 0.02, 0.999
25
  # (this is the forward diffusion process)
26
  noise = torch.randn(clean_z.shape).to(pipe.device)
27
  timestep = torch.Tensor([int(pipe.scheduler.config.num_train_timesteps * percent_noise)]).to(pipe.device).long()
28
- z = pipe.scheduler.add_noise(clean_z, noise, timestep).half()
 
 
29
 
30
  # Run the diffusion model
31
  #with autocast('cuda'):
 
6
 
7
  from boomerang import *
8
 
9
+
10
+ HALF_PRECISION = False
11
+
12
+
13
+
14
  def main(image, prompt, percent_noise): # percent_noise = 0.5, 0.02, 0.999
15
 
16
  # Convert image to float and preprocess it.
 
19
  T.ConvertImageDtype(torch.float),
20
  T.Normalize([0.5], [0.5])])
21
 
22
+ if HALF_PRECISION:
23
+ tensor = transform(image).half().to(pipe.device)
24
+ else:
25
+ tensor = transform(image).to(pipe.device)
26
  tensor = torch.unsqueeze(tensor, 0)
27
 
28
  # Project image into the latent space
 
33
  # (this is the forward diffusion process)
34
  noise = torch.randn(clean_z.shape).to(pipe.device)
35
  timestep = torch.Tensor([int(pipe.scheduler.config.num_train_timesteps * percent_noise)]).to(pipe.device).long()
36
+ z = pipe.scheduler.add_noise(clean_z, noise, timestep)
37
+ if HALF_PRECISION:
38
+ z = z.half()
39
 
40
  # Run the diffusion model
41
  #with autocast('cuda'):