Open pramitchoudhary opened 1 year ago
Guided impromptu generation using Stable Diffuse
https://github.com/CompVis/stable-diffusion
https://github.com/huggingface/diffusers
[ ] Basic code:
import requests import torch from torch import autocast from PIL import Image from io import BytesIO from diffusers import StableDiffusionImg2ImgPipeline
from PIL import Image image_input = Image.open("...").convert("RGB") init_image = image_input.resize((768, 512))
device = "cuda" model_id_or_path = "CompVis/stable-diffusion-v1-4" pipe = StableDiffusionImg2ImgPipeline.from_pretrained("../diffuser_fun/stable-diffusion-v1-4" pipe = pipe.to(device)
prompt = "oil painting" with autocast(device): images = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5)["sample"]
images[0].save("oil_paiting.png")
from matplotlib.pyplot import imshow import numpy as np %matplotlib inline
pil_im = Image.open('oil_paiting.png', 'r') imshow(np.asarray(pil_im))
- [ ] With re-training to customize
Guided impromptu generation using Stable Diffuse
https://github.com/CompVis/stable-diffusion
https://github.com/huggingface/diffusers
[ ] Basic code:
Upload image
from PIL import Image image_input = Image.open("...").convert("RGB") init_image = image_input.resize((768, 512))
device = "cuda" model_id_or_path = "CompVis/stable-diffusion-v1-4" pipe = StableDiffusionImg2ImgPipeline.from_pretrained("../diffuser_fun/stable-diffusion-v1-4" pipe = pipe.to(device)
prompt = "oil painting" with autocast(device): images = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5)["sample"]
images[0].save("oil_paiting.png")
from matplotlib.pyplot import imshow import numpy as np %matplotlib inline
pil_im = Image.open('oil_paiting.png', 'r') imshow(np.asarray(pil_im))