-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_text2image.py
More file actions
executable file
·82 lines (72 loc) · 2.34 KB
/
example_text2image.py
File metadata and controls
executable file
·82 lines (72 loc) · 2.34 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import torch
import random
import argparse
import numpy as np
from consist_compose import ConsistComposeBagelModel
def set_seed(seed=42):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
def main():
parser = argparse.ArgumentParser(
description="ConsistCompose layout control image generation example - generate image from text prompt with ICBP paradigm"
)
parser.add_argument(
"--model_path",
type=str,
default="sensenova/ConsistCompose-BAGEL-7B-MoT",
help="BAGEL model path",
)
parser.add_argument(
"--prompt",
type=str,
default="A chubby cat made of 3D point clouds, stretching its body, translucent with a soft glow.",
help="Text prompt used to generate an image",
)
parser.add_argument(
"--mode",
type=str,
default="layout_t2i",
choices=["layout_t2i", "layout_subject_driven", "generate", "think_generate"],
help="BAGEL mode: generate or think_generate",
)
parser.add_argument(
"--out_img_dir",
type=str,
default="./output_images/layout_t2i/",
help="Directory to save generated images",
)
parser.add_argument(
"--dtype",
type=str,
default="bf16",
choices=["bf16"],
help="Model precision type",
)
args = parser.parse_args()
print(f"Model path: {args.model_path}")
print(f"Mode: {args.mode}")
print(f"Prompt: {args.prompt}")
print("-" * 50)
# Initialize BAGEL model with generate mode
print("\nLoading ConsistCompose model...")
model = ConsistComposeBagelModel(
model_path=args.model_path,
out_img_dir=args.out_img_dir,
dtype=args.dtype,
)
# Set random seed for reproducibility
set_seed()
print("Generating image...")
# Call generate with the prompt; images not needed for generate mode
generated_image_path = model.generate(question=args.prompt, images=None, mode=args.mode, vis_bbox=True, resize_short_edge=768)
print("-" * 50)
print("Done!")
print(f"Image saved to: {generated_image_path}")
if __name__ == "__main__":
main()