Skip to content

Commit

Permalink
[IF super res] correctly normalize PIL input (huggingface#3536)
Browse files Browse the repository at this point in the history
* [IF super res] correctl normalize PIL input

* 175 -> 127.5
  • Loading branch information
williamberman authored May 26, 2023
1 parent 1d1f648 commit bdc75e7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def preprocess_image(self, image: PIL.Image.Image, num_images_per_prompt, device
image = [image]

if isinstance(image[0], PIL.Image.Image):
image = [np.array(i).astype(np.float32) / 255.0 for i in image]
image = [np.array(i).astype(np.float32) / 127.5 - 1.0 for i in image]

image = np.stack(image, axis=0) # to np
image = torch.from_numpy(image.transpose(0, 3, 1, 2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ def preprocess_image(self, image: PIL.Image.Image, num_images_per_prompt, device
image = [image]

if isinstance(image[0], PIL.Image.Image):
image = [np.array(i).astype(np.float32) / 255.0 for i in image]
image = [np.array(i).astype(np.float32) / 127.5 - 1.0 for i in image]

image = np.stack(image, axis=0) # to np
image = torch.from_numpy(image.transpose(0, 3, 1, 2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def preprocess_image(self, image, num_images_per_prompt, device):
image = [image]

if isinstance(image[0], PIL.Image.Image):
image = [np.array(i).astype(np.float32) / 255.0 for i in image]
image = [np.array(i).astype(np.float32) / 127.5 - 1.0 for i in image]

image = np.stack(image, axis=0) # to np
image = torch.from_numpy(image.transpose(0, 3, 1, 2))
Expand Down

0 comments on commit bdc75e7

Please sign in to comment.