Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A suggestion in unit3 #38

Open
yizhangliu opened this issue Dec 25, 2022 · 0 comments
Open

A suggestion in unit3 #38

yizhangliu opened this issue Dec 25, 2022 · 0 comments

Comments

@yizhangliu
Copy link

https://colab.research.google.com/github/huggingface/diffusion-models-class/blob/main/unit3/01_stable_diffusion_introduction.ipynb

from torchvision import transforms
display(init_image)
# pil image convert to torch.tensor
images = transforms.Compose([transforms.ToTensor()])(init_image).unsqueeze(0).to(device,torch.float)
print("Input images shape:", images.shape)

# Encode to latent space
with torch.no_grad():
  latents = 0.18215 * pipe.vae.encode(images).latent_dist.mean
print("Encoded latents shape:", latents.shape)

# Decode again
with torch.no_grad():
  decoded_images = pipe.vae.decode(latents / 0.18215).sample
print("Decoded images shape:", decoded_images.shape)
display(transforms.functional.to_pil_image(decoded_images[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant