|
| 1 | +<!--Copyright 2022 The HuggingFace Team. All rights reserved. |
| 2 | + |
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 4 | +the License. You may obtain a copy of the License at |
| 5 | + |
| 6 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + |
| 8 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 9 | +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | +specific language governing permissions and limitations under the License. |
| 11 | +--> |
| 12 | + |
| 13 | +# Stable unCLIP |
| 14 | + |
| 15 | +The stable unCLIP model is [stable diffusion 2.1](./stable_diffusion_2) finetuned to condition on CLIP image embeddings. |
| 16 | +Stable unCLIP also still conditions on text embeddings. Given the two separate conditionings, stable unCLIP can be used |
| 17 | +for text guided image variation. When combined with an unCLIP prior, it can also be used for full text to image generation. |
| 18 | + |
| 19 | +## Tips |
| 20 | + |
| 21 | +Stable unCLIP takes a `noise_level` as input during inference. `noise_level` determines how much noise is added |
| 22 | +to the image embeddings. A higher `noise_level` increases variation in the final un-noised images. By default, |
| 23 | +we do not add any additional noise to the image embeddings i.e. `noise_level = 0`. |
| 24 | + |
| 25 | +### Available checkpoints: |
| 26 | + |
| 27 | +TODO |
| 28 | + |
| 29 | +### Text-to-Image Generation |
| 30 | + |
| 31 | +```python |
| 32 | +import torch |
| 33 | +from diffusers import StableUnCLIPPipeline |
| 34 | + |
| 35 | +pipe = StableUnCLIPPipeline.from_pretrained( |
| 36 | + "fusing/stable-unclip-2-1-l", torch_dtype=torch.float16 |
| 37 | +) # TODO update model path |
| 38 | +pipe = pipe.to("cuda") |
| 39 | + |
| 40 | +prompt = "a photo of an astronaut riding a horse on mars" |
| 41 | +images = pipe(prompt).images |
| 42 | +images[0].save("astronaut_horse.png") |
| 43 | +``` |
| 44 | + |
| 45 | + |
| 46 | +### Text guided Image-to-Image Variation |
| 47 | + |
| 48 | +```python |
| 49 | +import requests |
| 50 | +import torch |
| 51 | +from PIL import Image |
| 52 | +from io import BytesIO |
| 53 | + |
| 54 | +from diffusers import StableUnCLIPImg2ImgPipeline |
| 55 | + |
| 56 | +pipe = StableUnCLIPImg2ImgPipeline.from_pretrained( |
| 57 | + "fusing/stable-unclip-2-1-l-img2img", torch_dtype=torch.float16 |
| 58 | +) # TODO update model path |
| 59 | +pipe = pipe.to("cuda") |
| 60 | + |
| 61 | +url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" |
| 62 | + |
| 63 | +response = requests.get(url) |
| 64 | +init_image = Image.open(BytesIO(response.content)).convert("RGB") |
| 65 | +init_image = init_image.resize((768, 512)) |
| 66 | + |
| 67 | +prompt = "A fantasy landscape, trending on artstation" |
| 68 | + |
| 69 | +images = pipe(prompt, init_image).images |
| 70 | +images[0].save("fantasy_landscape.png") |
| 71 | +``` |
| 72 | + |
| 73 | +### StableUnCLIPPipeline |
| 74 | + |
| 75 | +[[autodoc]] StableUnCLIPPipeline |
| 76 | + - all |
| 77 | + - __call__ |
| 78 | + - enable_attention_slicing |
| 79 | + - disable_attention_slicing |
| 80 | + - enable_vae_slicing |
| 81 | + - disable_vae_slicing |
| 82 | + - enable_xformers_memory_efficient_attention |
| 83 | + - disable_xformers_memory_efficient_attention |
| 84 | + |
| 85 | + |
| 86 | +### StableUnCLIPImg2ImgPipeline |
| 87 | + |
| 88 | +[[autodoc]] StableUnCLIPImg2ImgPipeline |
| 89 | + - all |
| 90 | + - __call__ |
| 91 | + - enable_attention_slicing |
| 92 | + - disable_attention_slicing |
| 93 | + - enable_vae_slicing |
| 94 | + - disable_vae_slicing |
| 95 | + - enable_xformers_memory_efficient_attention |
| 96 | + - disable_xformers_memory_efficient_attention |
| 97 | + |
0 commit comments