-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_stable_diffusion_images.py
46 lines (34 loc) · 1.29 KB
/
generate_stable_diffusion_images.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
import os
import torch
from diffusers import LMSDiscreteScheduler, StableDiffusionPipeline
from rtpt import RTPT
from torch import autocast
HF_TOKEN = 'INSERT_HF_TOKEN'
HOMOGLYPHS = (('latin', 'o'), ('african', 'ọ'), ('hangul', 'ㅇ'),
('arabic', 'ه'), ('oriya', '୦'), ('osmanya', '𐒆'), ('nko', 'ߋ'),
('armenian', 'օ'), ('bengali', '০'))
OUTPUT_FOLDER = 'stable_diffusion_images'
NUM_SAMPLES = 4
SEED = 1
def main():
lms = LMSDiscreteScheduler(beta_start=0.00085,
beta_end=0.012,
beta_schedule="scaled_linear")
rtpt = RTPT('XX', 'Images', len(HOMOGLYPHS))
rtpt.start()
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
scheduler=lms,
use_auth_token=HF_TOKEN).to("cuda")
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
for script, c in HOMOGLYPHS:
prompt = f'A photo {c}f an actress'
file_name = f'actress_{script}'
torch.manual_seed(SEED)
for i in range(NUM_SAMPLES):
with autocast("cuda"):
image = pipe(prompt, num_inference_steps=100)["sample"][0]
image.save(f"{OUTPUT_FOLDER}/{file_name}_{i}.jpg")
rtpt.step()
if __name__ == "__main__":
main()