Norod78 commited on
Commit
3682911
·
1 Parent(s): ed954c9

Upload sd15-arthur-generate-samples.py

Browse files
Files changed (1) hide show
  1. sd15-arthur-generate-samples.py +66 -0
sd15-arthur-generate-samples.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
3
+ import torch
4
+
5
+ #////////////////////////////////////////////////////////////////
6
+ guidance_scale=8.0
7
+ steps=40
8
+ width=512
9
+ height=512
10
+
11
+ prompt_suffix = ", Very detailed, clean, high quality, sharp image"
12
+ #////////////////////////////////////////////////////////////////
13
+ custom_model_id = "Norod78/sd15-arthur-blip-captions"
14
+ #////////////////////////////////////////////////////////////////
15
+ custom_model_id_str = custom_model_id.replace("/","_")
16
+ custom_model_pipe = None
17
+
18
+ def generate(prompt, file_prefix ,samples, seed):
19
+ global base_model_pipe, custom_model_pipe
20
+
21
+ torch.manual_seed(seed)
22
+ prompt += prompt_suffix
23
+ file_prefix += "Arthur"
24
+ custom_model_images = custom_model_pipe([prompt] * samples, num_inference_steps=steps, guidance_scale=guidance_scale, height=height, width=width)["images"]
25
+ for idx, image in enumerate(custom_model_images):
26
+ image.save(f"{file_prefix}-{idx}-{seed}--{width}x{height}-{custom_model_id_str}.jpg")
27
+
28
+ def load():
29
+ global base_model_pipe, custom_model_pipe
30
+
31
+ scheduler = DPMSolverMultistepScheduler(
32
+ beta_start=0.00085,
33
+ beta_end=0.012,
34
+ beta_schedule="scaled_linear",
35
+ num_train_timesteps=1000,
36
+ trained_betas=None,
37
+ thresholding=False,
38
+ algorithm_type="dpmsolver++",
39
+ solver_type="midpoint",
40
+ lower_order_final=True,
41
+ )
42
+
43
+ device = "cuda" if torch.cuda.is_available() else "cpu"
44
+ dtype = torch.float16 if device == "cuda" else torch.float32
45
+ custom_model_pipe = StableDiffusionPipeline.from_pretrained(custom_model_id, scheduler=scheduler,torch_dtype=dtype).to(device)
46
+
47
+ def main():
48
+ load()
49
+
50
+ generate("A livingroom", "01_LivingRoom", 4, 555)
51
+ generate("Nicolas Cage, in \"The Minions\" movie", "02_NicolasCage", 2, 42)
52
+ generate("Gal Gadot as wonderwoman", "03_GalGadot", 2, 42)
53
+ generate("Gal Gadot in Avatar", "04_GalGadotAvatar", 2, 777)
54
+ generate("Family guy taking selfies at the beach", "05_FamilyGuy", 2, 555)
55
+ generate("Pikachu as Rick and morty, Eric Wallis", "06_PikachuRnM", 2, 777)
56
+ generate("Pikachu as Spongebob, Eric Wallis", "07_PikachuSpongeBob", 2, 42)
57
+ generate("An oil painting of Miss. Piggy from the muppets as the Mona Lisa", "08_MsPiggyMonaLisa", 2, 42)
58
+ generate("Rick Sanchez from the TV show \"Rick and Morty\"", "09_RickSanchez", 2, 42)
59
+ generate("An paiting of Southpark with rainbow", "10_Southpark", 2, 777)
60
+ generate("A psychedelic image of Bojack Horseman", "11_Bojack", 2, 777)
61
+ generate("A movie poster for Gravity Falls Cthulhu stories", "12_GravityFalls", 2, 777)
62
+ generate("A vibrant oil painting portrait of She-Ra", "13_Shira", 2, 512)
63
+ #
64
+
65
+ if __name__ == '__main__':
66
+ main()