forked from fchollet/stable-diffusion-tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text2image.py
56 lines (50 loc) · 1.21 KB
/
text2image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from stable_diffusion_tf.stable_diffusion import Text2Image
import argparse
from PIL import Image
parser = argparse.ArgumentParser()
parser.add_argument(
"--prompt",
type=str,
nargs="?",
default="a painting of a virus monster playing guitar",
help="the prompt to render",
)
parser.add_argument(
"--output",
type=str,
nargs="?",
default="output.png",
help="where to save the output image",
)
parser.add_argument(
"--H",
type=int,
default=512,
help="image height, in pixels",
)
parser.add_argument(
"--W",
type=int,
default=512,
help="image width, in pixels",
)
parser.add_argument(
"--scale",
type=float,
default=7.5,
help="unconditional guidance scale: eps = eps(x, empty) + scale * (eps(x, cond) - eps(x, empty))",
)
parser.add_argument(
"--steps", type=int, default=50, help="number of ddim sampling steps"
)
args = parser.parse_args()
generator = Text2Image(img_height=args.H, img_width=args.W, jit_compile=False)
img = generator.generate(
args.prompt,
num_steps=args.steps,
unconditional_guidance_scale=args.scale,
temperature=1,
batch_size=1,
)
Image.fromarray(img[0]).save(args.output)
print(f"saved at {args.output}")