Skip to content

Instantly share code, notes, and snippets.

@toshvelaga
Created November 21, 2023 07:10
Show Gist options
  • Save toshvelaga/1d3d3812e2ee38d1f4af3bb612068881 to your computer and use it in GitHub Desktop.
Save toshvelaga/1d3d3812e2ee38d1f4af3bb612068881 to your computer and use it in GitHub Desktop.
import torch
from diffusers import StableDiffusionPipeline
import matplotlib.pyplot as plt
import time
begin = time.time()
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
# use_safetensors=True,
# local_files_only=True,
# device_map="auto",
# safety_checker=None
cache_dir="models",
)
print(f"Load : {time.time()-begin}")
pipe = pipe.to("cuda")
print(f"Load+cuda : {time.time()-begin}")
prompt = "native american chief"
image = pipe(prompt, num_inference_steps=25).images[0]
# If the image is a torch tensor, convert it to numpy array
if torch.is_tensor(image):
image = image.cpu().numpy()
# Display the image
plt.imshow(image)
plt.axis('off') # To turn off axis numbers
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment