-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample_panorama_lcm.py
63 lines (52 loc) · 2.25 KB
/
sample_panorama_lcm.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
63
from pathlib import Path
import argparse
import numpy as np
import torch
from merge_attend_lcm import MergeAttendLCM
from sampling_utils import seed_everything
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--prompt', type=str, default='Boyscout campfire at night')
parser.add_argument('--model_key', type=str, default='SimianLuo/LCM_Dreamshaper_v7')
parser.add_argument('--H', type=int, default=512)
parser.add_argument('--W', type=int, default=3072)
parser.add_argument('--steps', type=int, default=4)
parser.add_argument('--num_samples', type=int, default=3)
parser.add_argument('--save_dir', type=str, default='results')
parser.add_argument('--out_name', type=str, default='mad_lcd')
parser.add_argument('--dtype', type=str, default='fp32')
parser.add_argument('--mad_threshold', type=int, default=2)
parser.add_argument('--mad_blocks', type=str, default='all')
parser.add_argument('--stride', type=int, default=16, help='window stride for MultiDiffusion')
parser.add_argument('--seed', type=int)
args = parser.parse_args()
device = torch.device('cuda:0') if torch.cuda.is_available() else 'cpu'
if args.seed is not None:
seed_everything(args.seed)
# Load LCM model
model = MergeAttendLCM(args.model_key, device, args.dtype)
save_dir = Path(args.save_dir)
save_dir.mkdir(exist_ok=True, parents=True)
out_file = Path(args.out_name).stem
print(f"{device} - Prompt: {args.prompt}")
try:
for sample_idx in range(args.num_samples):
save_path = Path(save_dir) / args.prompt.replace(' ', '_') / f"{out_file}_{sample_idx:04d}.png"
save_path.parent.mkdir(exist_ok=True, parents=True)
# Generate images
img = model.sample(
prompts=args.prompt,
height=args.H,
width=args.W,
num_inference_steps=args.steps,
stride=args.stride,
mad_blocks=args.mad_blocks,
mad_threshold=args.mad_threshold
)
img.save(save_path)
torch.cuda.empty_cache()
except KeyboardInterrupt:
print(f"Interrupted! Saving results...")
print(f"Done!")
if __name__ == "__main__":
main()