Model reference · open weights
sd-image-variations is an open-weight image model from lambda. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.
Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.
What it is
| Released by | lambda |
|---|---|
| Type | Image models |
| Task | Image edit |
| Runs with | diffusers |
| Released | 2022-09-09 |
| Popularity | 2k downloads / month |
| Licence | Open weights |
About
📣 V2 model released, and blurriness issues fixed! 📣
🧨🎉 Image Variations is now natively supported in 🤗 Diffusers! 🎉🧨
This version of Stable Diffusion has been fine tuned from CompVis/stable-diffusion-v1-4-original to accept CLIP image embedding rather than text embeddings. This allows the creation of "image variations" similar to DALLE-2 using Stable Diffusion. This version of the weights has been ported to huggingface Diffusers, to use this with the Diffusers library requires the Lambda Diffusers repo.
This model was trained in two stages and longer than the original variations model and gives better image quality and better CLIP rated similarity compared to the original version
See training details and v1 vs v2 comparison below.
Make sure you are using a version of Diffusers >=0.8.0 (for older version see the old instructions at the bottom of this model card)
from diffusers import StableDiffusionImageVariationPipeline
from PIL import Image
device = "cuda:0"
sd_pipe = StableDiffusionImageVariationPipeline.from_pretrained(
"lambdalabs/sd-image-variations-diffusers",
revision="v2.0",
)
sd_pipe = sd_pipe.to(device)
im = Image.open("path/to/image.jpg")
tform = transforms.Compose([
transforms.ToTensor(),
transforms.Resize(
(224, 224),
interpolation=transforms.InterpolationMode.BICUBIC,
antialias=False,
),
transforms.Normalize(
[0.48145466, 0.4578275, 0.40821073],
[0.26862954, 0.26130258, 0.27577711]),
])
inp = tform(im).to(device).unsqueeze(0)
out = sd_pipe(inp, guidance_scale=3)
out["images"][0].save("result.jpg")
Note that due a bit of an oversight during training, the model expects resized images without anti-aliasing. This turns out to make a big difference and is important to do the resizing the same way during inference. When passing a PIL image to the Diffusers pipeline antialiasing will be applied during resize, so it's better to input a tensor which you have prepared manually according to the transfrom in the example above!
Here are examples of images generated without (top) and with (bottom) anti-aliasing during resize. (Input is this image)
Here's an example of V1 vs V2, version two was trained more carefully and for longer, see the details below. V2-top vs V1-bottom
Input images:
One important thing to note is that due to the longer training V2 appears to have memorised some common images from the training data, e.g. now the previous example of the Girl with a Pearl Earring almosts perfectly reproduce the original rather than creating variations. You can always use v1 by specifiying revision="v1.0".
v2 output for girl with a pearl earing as input (guidance scale=3)
Training Procedure This model is fine tuned from Stable Diffusion v1-3 where the text encoder has been replaced with an image encoder. The training procedure is the same as for Stable Diffusion except for the fact that images are encoded through a ViT-L/14 image-encoder including the final projection layer to the CLIP shared embedding space. The model was trained on LAION improved aesthetics 6plus.
Hardware: 8 x A100-40GB GPUs (provided by Lambda GPU Cloud)
Optimizer: AdamW
Stage 1 - Fine tune only CrossAttention layer weights from Stable Diffusion v1.4 model
Stage 2 - Resume from Stage 1 training the whole unet
Training was done using a modified version of the original Stable Diffusion training code.
The following section is adapted from the Stable Diffusion model card
The model is intended for research purposes only. Possible research areas and tasks include
Excluded uses are described below.
The model should not be used to intentionally create or disseminate images that create hostile or alienating environments for people. This includes generating images that people would foreseeably find disturbing, distressing, or offensive; or content that propagates historical or current stereotypes.
The model was not trained to be factual or true representations of people or events, and therefore using the model to generate such content is out-of-scope for the abilities of this model.
Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
From the published model card. Full card on the HuggingFace links in the sidebar.
How it works
Using it via the API
Once AxForge deploys sd-image-variations for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (sd-image-variations below is illustrative; you get the exact model name on deployment.)
$ curl -sS https://api.axforge.ai/v1/images/generations \
-H "Authorization: Bearer $AXFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"sd-image-variations","prompt":"a red bicycle","size":"1024x1024"}'
Create an account — your API key is available in the console. 3M free tokens every 30 days with every new account.