File size: 4,072 Bytes
76a5c1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
739f10e
76a5c1c
739f10e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
dataset_info:
  features:
  - name: Prompt
    dtype: string
  - name: Category
    dtype: string
  - name: Challenge
    dtype: string
  - name: Note
    dtype: string
  - name: images
    dtype: image
  - name: model_name
    dtype: string
  - name: seed
    dtype: int64
  - name: upvotes
    dtype: int64
  splits:
  - name: train
    num_bytes: 25650684.0
    num_examples: 219
  download_size: 25640015
  dataset_size: 25650684.0
configs:
- config_name: default
  data_files:
  - split: train
    path: data/train-*
---
# SDXL

All images included in this dataset were voted as "Not solved" by the community in https://huggingface.co/spaces/OpenGenAI/open-parti-prompts.
This means that according to the community the model did not generate an image that corresponds sufficiently enough to the prompt.

The following script was used to generate the images:

```py
import torch
from datasets import Dataset, Features
from datasets import Image as ImageFeature
from datasets import Value, load_dataset

from diffusers import DDIMScheduler, DiffusionPipeline
import PIL


def main():
    print("Loading dataset...")
    parti_prompts = load_dataset("nateraw/parti-prompts", split="train")

    print("Loading pipeline...")
    ckpt_id = "stabilityai/stable-diffusion-xl-base-1.0"
    refiner_ckpt_id = "stabilityai/stable-diffusion-xl-refiner-1.0"

    pipe = DiffusionPipeline.from_pretrained(
        ckpt_id, torch_dtype=torch.float16, use_auth_token=True
    ).to("cuda")
    pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
    pipe.set_progress_bar_config(disable=True)
    refiner = DiffusionPipeline.from_pretrained(
        refiner_ckpt_id,
        torch_dtype=torch.float16,
        use_auth_token=True
    ).to("cuda")
    refiner.scheduler = DDIMScheduler.from_config(refiner.scheduler.config)
    refiner.set_progress_bar_config(disable=True)

    seed = 0
    generator = torch.Generator("cuda").manual_seed(seed)

    print("Running inference...")
    main_dict = {}
    for i in range(len(parti_prompts)):
        sample = parti_prompts[i]
        prompt = sample["Prompt"]
        latent = pipe(
            prompt,
            generator=generator,
            num_inference_steps=100,
            guidance_scale=7.5,
            output_type="latent",
        ).images[0]
        image_refined = refiner(
            prompt=prompt,
            image=latent[None, :],
            generator=generator,
            num_inference_steps=100,
            guidance_scale=7.5,
        ).images[0]

        image = image_refined.resize((256, 256), resample=PIL.Image.Resampling.LANCZOS)
        img_path = f"sd_xl_{i}.png"
        image.save(img_path)
        main_dict.update(
            {
                prompt: {
                    "img_path": img_path,
                    "Category": sample["Category"],
                    "Challenge": sample["Challenge"],
                    "Note": sample["Note"],
                    "model_name": ckpt_id,
                    "seed": seed,
                }
            }
        )

    def generation_fn():
        for prompt in main_dict:
            prompt_entry = main_dict[prompt]
            yield {
                "Prompt": prompt,
                "Category": prompt_entry["Category"],
                "Challenge": prompt_entry["Challenge"],
                "Note": prompt_entry["Note"],
                "images": {"path": prompt_entry["img_path"]},
                "model_name": prompt_entry["model_name"],
                "seed": prompt_entry["seed"],
            }

    print("Preparing HF dataset...")
    ds = Dataset.from_generator(
        generation_fn,
        features=Features(
            Prompt=Value("string"),
            Category=Value("string"),
            Challenge=Value("string"),
            Note=Value("string"),
            images=ImageFeature(),
            model_name=Value("string"),
            seed=Value("int64"),
        ),
    )
    ds_id = "diffusers-parti-prompts/sdxl-1.0-refiner"
    ds.push_to_hub(ds_id)


if __name__ == "__main__":
    main()
```