"git@developer.sourcefind.cn:OpenDAS/fairscale.git" did not exist on "99b30a049ecfd98e37244672b1d8db0774ecb9b4"
Unverified Commit aa3c46d9 authored by v2ray's avatar v2ray Committed by GitHub
Browse files

[Doc] Improved level of clarity for latents_to_rgb. (#9529)



Fixed latents_to_rgb doc.
Co-authored-by: default avatarÁlvaro Somoza <asomoza@users.noreply.github.com>
parent c76e8840
...@@ -171,14 +171,13 @@ def latents_to_rgb(latents): ...@@ -171,14 +171,13 @@ def latents_to_rgb(latents):
weights = ( weights = (
(60, -60, 25, -70), (60, -60, 25, -70),
(60, -5, 15, -50), (60, -5, 15, -50),
(60, 10, -5, -35) (60, 10, -5, -35),
) )
weights_tensor = torch.t(torch.tensor(weights, dtype=latents.dtype).to(latents.device)) weights_tensor = torch.t(torch.tensor(weights, dtype=latents.dtype).to(latents.device))
biases_tensor = torch.tensor((150, 140, 130), dtype=latents.dtype).to(latents.device) biases_tensor = torch.tensor((150, 140, 130), dtype=latents.dtype).to(latents.device)
rgb_tensor = torch.einsum("...lxy,lr -> ...rxy", latents, weights_tensor) + biases_tensor.unsqueeze(-1).unsqueeze(-1) rgb_tensor = torch.einsum("...lxy,lr -> ...rxy", latents, weights_tensor) + biases_tensor.unsqueeze(-1).unsqueeze(-1)
image_array = rgb_tensor.clamp(0, 255)[0].byte().cpu().numpy() image_array = rgb_tensor.clamp(0, 255).byte().cpu().numpy().transpose(1, 2, 0)
image_array = image_array.transpose(1, 2, 0)
return Image.fromarray(image_array) return Image.fromarray(image_array)
``` ```
...@@ -189,7 +188,7 @@ def latents_to_rgb(latents): ...@@ -189,7 +188,7 @@ def latents_to_rgb(latents):
def decode_tensors(pipe, step, timestep, callback_kwargs): def decode_tensors(pipe, step, timestep, callback_kwargs):
latents = callback_kwargs["latents"] latents = callback_kwargs["latents"]
image = latents_to_rgb(latents) image = latents_to_rgb(latents[0])
image.save(f"{step}.png") image.save(f"{step}.png")
return callback_kwargs return callback_kwargs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment