sayakpaul HF Staff commited on
Commit
1428194
·
1 Parent(s): d0b3dba

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +106 -1
README.md CHANGED
@@ -24,4 +24,109 @@ dataset_info:
24
  ---
25
  # Dataset Card for "kandinsky-2-2"
26
 
27
- [More Information needed](https://github.com/huggingface/datasets/blob/main/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  ---
25
  # Dataset Card for "kandinsky-2-2"
26
 
27
+ The dataset was generated using the code below:
28
+
29
+ ```python
30
+ import PIL
31
+ import torch
32
+ from datasets import Dataset, Features
33
+ from datasets import Image as ImageFeature
34
+ from datasets import Value, load_dataset
35
+
36
+ from diffusers import DDIMScheduler, DiffusionPipeline
37
+
38
+
39
+ def main():
40
+ print("Loading dataset...")
41
+ parti_prompts = load_dataset("nateraw/parti-prompts", split="train")
42
+
43
+ print("Loading pipeline...")
44
+ pipe_prior = DiffusionPipeline.from_pretrained(
45
+ "kandinsky-community/kandinsky-2-2-prior", torch_dtype=torch.float16
46
+ )
47
+ pipe_prior.to("cuda")
48
+ pipe_prior.set_progress_bar_config(disable=True)
49
+
50
+ t2i_pipe = DiffusionPipeline.from_pretrained(
51
+ "kandinsky-community/kandinsky-2-2-decoder", torch_dtype=torch.float16
52
+ )
53
+ t2i_pipe.scheduler = DDIMScheduler.from_config(t2i_pipe.scheduler.config)
54
+ t2i_pipe.to("cuda")
55
+ t2i_pipe.set_progress_bar_config(disable=True)
56
+
57
+ seed = 0
58
+ generator = torch.Generator("cuda").manual_seed(seed)
59
+ ckpt_id = (
60
+ "kandinsky-community/" + "kandinsky-2-2-prior" + "_" + "kandinsky-2-2-decoder"
61
+ )
62
+
63
+ print("Running inference...")
64
+ main_dict = {}
65
+ for i in range(len(parti_prompts)):
66
+ sample = parti_prompts[i]
67
+ prompt = sample["Prompt"]
68
+
69
+ image_embeds, negative_image_embeds = pipe_prior(
70
+ prompt,
71
+ generator=generator,
72
+ num_inference_steps=100,
73
+ guidance_scale=7.5,
74
+ ).to_tuple()
75
+ image = t2i_pipe(
76
+ image_embeds=image_embeds,
77
+ negative_image_embeds=negative_image_embeds,
78
+ generator=generator,
79
+ num_inference_steps=100,
80
+ guidance_scale=7.5,
81
+ ).images[0]
82
+
83
+ image = image.resize((256, 256), resample=PIL.Image.Resampling.LANCZOS)
84
+ img_path = f"kandinsky_22_{i}.png"
85
+ image.save(img_path)
86
+ main_dict.update(
87
+ {
88
+ prompt: {
89
+ "img_path": img_path,
90
+ "Category": sample["Category"],
91
+ "Challenge": sample["Challenge"],
92
+ "Note": sample["Note"],
93
+ "model_name": ckpt_id,
94
+ "seed": seed,
95
+ }
96
+ }
97
+ )
98
+
99
+ def generation_fn():
100
+ for prompt in main_dict:
101
+ prompt_entry = main_dict[prompt]
102
+ yield {
103
+ "Prompt": prompt,
104
+ "Category": prompt_entry["Category"],
105
+ "Challenge": prompt_entry["Challenge"],
106
+ "Note": prompt_entry["Note"],
107
+ "images": {"path": prompt_entry["img_path"]},
108
+ "model_name": prompt_entry["model_name"],
109
+ "seed": prompt_entry["seed"],
110
+ }
111
+
112
+ print("Preparing HF dataset...")
113
+ ds = Dataset.from_generator(
114
+ generation_fn,
115
+ features=Features(
116
+ Prompt=Value("string"),
117
+ Category=Value("string"),
118
+ Challenge=Value("string"),
119
+ Note=Value("string"),
120
+ images=ImageFeature(),
121
+ model_name=Value("string"),
122
+ seed=Value("int64"),
123
+ ),
124
+ )
125
+ ds_id = "diffusers-parti-prompts/kandinsky-2-2"
126
+ ds.push_to_hub(ds_id)
127
+
128
+
129
+ if __name__ == "__main__":
130
+ main()
131
+
132
+ ```