fpramunno commited on
Commit
3d25cfa
1 Parent(s): 8698210

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -1
app.py CHANGED
@@ -69,10 +69,12 @@ def generate_image(seed_image):
69
 
70
  generated_image = diffusion.sample(model, y=input_img_pil, labels=None, n=1)
71
 
72
- inp_img = input_img_pil.reshape(1, 256, 256).permute(1, 2, 0)
 
73
  inp_img = np.squeeze(inp_img.cpu().numpy())
74
  inp = Image.fromarray(inp_img) # Create a PIL Image from array
75
  inp = inp.transpose(Image.FLIP_TOP_BOTTOM)
 
76
  img = generated_image[0].reshape(1, 256, 256).permute(1, 2, 0) # Permute dimensions to height x width x channels
77
  img = np.squeeze(img.cpu().numpy())
78
  v = Image.fromarray(img) # Create a PIL Image from array
 
69
 
70
  generated_image = diffusion.sample(model, y=input_img_pil, labels=None, n=1)
71
 
72
+ inp_img = (inp_img.clamp(-1, 1) + 1) / 2 # to be in [-1, 1], the plus 1 and the division by 2 is to bring back values to [0, 1]
73
+ inp_img = (inp_img * 255).type(torch.uint8) # to bring in valid pixel range
74
  inp_img = np.squeeze(inp_img.cpu().numpy())
75
  inp = Image.fromarray(inp_img) # Create a PIL Image from array
76
  inp = inp.transpose(Image.FLIP_TOP_BOTTOM)
77
+
78
  img = generated_image[0].reshape(1, 256, 256).permute(1, 2, 0) # Permute dimensions to height x width x channels
79
  img = np.squeeze(img.cpu().numpy())
80
  v = Image.fromarray(img) # Create a PIL Image from array