-
Notifications
You must be signed in to change notification settings - Fork 228
/
img2img.py
62 lines (53 loc) · 1.19 KB
/
img2img.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
57
58
59
60
61
62
import argparse
from stable_diffusion_tf.stable_diffusion import StableDiffusion
from PIL import Image
parser = argparse.ArgumentParser()
parser.add_argument(
"--prompt",
type=str,
nargs="?",
required=True,
help="the prompt to render",
)
parser.add_argument(
"--negative-prompt",
type=str,
help="the negative prompt to use (if any)",
)
parser.add_argument(
"--steps",
type=int,
default=50,
help="number of ddim sampling steps"
)
parser.add_argument(
"--input",
type=str,
nargs="?",
required=True,
help="the input image filename",
)
parser.add_argument(
"--output",
type=str,
nargs="?",
default="img2img-out.jpeg",
help="the output image filename",
)
args = parser.parse_args()
generator = StableDiffusion(
img_height=512,
img_width=512,
jit_compile=False, # You can try True as well (different performance profile)
)
img = generator.generate(
args.prompt,
negative_prompt=args.negative_prompt,
num_steps=args.steps,
unconditional_guidance_scale=7.5,
temperature=1,
batch_size=1,
input_image=args.input,
input_image_strength=0.8
)
Image.fromarray(img[0]).save(args.output)