Last active
December 1, 2022 11:33
-
-
Save Norod/b7d06db33fab0b368bb3368ad6d23c0c to your computer and use it in GitHub Desktop.
Like the default HF StableDiffusion img2img sample, only it uses the sd2-simpsons-blip and DPMSolverMultistepScheduler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import torch | |
| from PIL import Image | |
| from io import BytesIO | |
| from diffusers import StableDiffusionImg2ImgPipeline, DPMSolverMultistepScheduler | |
| def main(): | |
| #//////////////////////////////////////////// | |
| seed = 42 | |
| num_inference_steps = 10 | |
| model_id_or_path = "Norod78/sd2-simpsons-blip" | |
| #//////////////////////////////////////////// | |
| scheduler = DPMSolverMultistepScheduler( | |
| beta_start=0.00085, | |
| beta_end=0.012, | |
| beta_schedule="scaled_linear", | |
| num_train_timesteps=1000, | |
| trained_betas=None, | |
| predict_epsilon=True, | |
| thresholding=False, | |
| algorithm_type="dpmsolver++", | |
| solver_type="midpoint", | |
| lower_order_final=True, | |
| ) | |
| # load the pipeline | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| dtype = torch.float16 if device == "cuda" else torch.float32 | |
| torch.manual_seed(seed) | |
| generator = torch.Generator() | |
| generator.manual_seed(seed) | |
| pipe = StableDiffusionImg2ImgPipeline.from_pretrained( | |
| model_id_or_path, | |
| torch_dtype=dtype, | |
| use_auth_token=True | |
| ) | |
| pipe.scheduler = scheduler | |
| pipe = pipe.to(device) | |
| # let's download an initial image | |
| url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" | |
| response = requests.get(url) | |
| init_image = Image.open(BytesIO(response.content)).convert("RGB") | |
| #init_image = Image.open('Me_segmented.png').convert('RGB') | |
| init_image = init_image.resize((768, 512)) | |
| prompt = "A fantasy landscape, trending on artstation" | |
| images = pipe(prompt=prompt, init_image=init_image, num_inference_steps= num_inference_steps, strength=0.75, guidance_scale=7.5, generator=generator).images | |
| images[0].save("fantasy_landscape.png") | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment