@@ -31,21 +31,33 @@ A fine-tuned version of Stable Diffusion conditioned on CLIP image embeddings to
31
31
### Usage
32
32
33
33
``` python
34
- from pathlib import Path
35
- from lambda_diffusers import StableDiffusionImageEmbedPipeline
34
+ from diffusers import StableDiffusionImageVariationPipeline
36
35
from PIL import Image
37
- import torch
38
- device = " cuda" if torch.cuda.is_available() else " cpu"
39
- pipe = StableDiffusionImageEmbedPipeline.from_pretrained(" lambdalabs/sd-image-variations-diffusers" )
40
- pipe = pipe.to(device)
41
- im = Image.open(" your/input/image/here.jpg" )
42
- num_samples = 4
43
- image = pipe(num_samples* [im], guidance_scale = 3.0 )
44
- image = image[" sample" ]
45
- base_path = Path(" outputs/im2im" )
46
- base_path.mkdir(exist_ok = True , parents = True )
47
- for idx, im in enumerate (image):
48
- im.save(base_path/ f " { idx:06 } .jpg " )
36
+
37
+ device = " cuda:0"
38
+ sd_pipe = StableDiffusionImageVariationPipeline.from_pretrained(
39
+ " lambdalabs/sd-image-variations-diffusers" ,
40
+ revision = " v2.0" ,
41
+ )
42
+ sd_pipe = sd_pipe.to(device)
43
+
44
+ im = Image.open(" path/to/image.jpg" )
45
+ tform = transforms.Compose([
46
+ transforms.ToTensor(),
47
+ transforms.Resize(
48
+ (224 , 224 ),
49
+ interpolation = transforms.InterpolationMode.BICUBIC ,
50
+ antialias = False ,
51
+ ),
52
+ transforms.Normalize(
53
+ [0.48145466 , 0.4578275 , 0.40821073 ],
54
+ [0.26862954 , 0.26130258 , 0.27577711 ]),
55
+ ])
56
+ inp = tform(im).to(device)
57
+
58
+ out = sd_pipe(inp, guidance_scale = 3 )
59
+ out[" images" ][0 ].save(" result.jpg" )
60
+
49
61
```
50
62
51
63
## Pokemon text to image
0 commit comments