Commit
·
be2721c
1
Parent(s):
b704080
Update README.md
Browse files
README.md
CHANGED
|
@@ -29,4 +29,115 @@ dataset_info:
|
|
| 29 |
---
|
| 30 |
# Dataset Card for "muse_512"
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
---
|
| 30 |
# Dataset Card for "muse_512"
|
| 31 |
|
| 32 |
+
```py
|
| 33 |
+
```py
|
| 34 |
+
from PIL import Image
|
| 35 |
+
import torch
|
| 36 |
+
from muse import PipelineMuse, MaskGiTUViT
|
| 37 |
+
from datasets import Dataset, Features
|
| 38 |
+
from datasets import Image as ImageFeature
|
| 39 |
+
from datasets import Value, load_dataset
|
| 40 |
+
|
| 41 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 42 |
+
|
| 43 |
+
pipe = PipelineMuse.from_pretrained(
|
| 44 |
+
transformer_path="valhalla/research-run",
|
| 45 |
+
text_encoder_path="openMUSE/clip-vit-large-patch14-text-enc",
|
| 46 |
+
vae_path="openMUSE/vqgan-f16-8192-laion",
|
| 47 |
+
).to(device)
|
| 48 |
+
|
| 49 |
+
pipe.transformer = MaskGiTUViT.from_pretrained("valhalla/research-run-finetuned-journeydb", revision="06bcd6ab6580a2ed3275ddfc17f463b8574457da", subfolder="ema_model").to(device)
|
| 50 |
+
pipe.tokenizer.pad_token_id = 49407
|
| 51 |
+
|
| 52 |
+
if device == "cuda":
|
| 53 |
+
pipe.transformer.enable_xformers_memory_efficient_attention()
|
| 54 |
+
pipe.text_encoder.to(torch.float16)
|
| 55 |
+
pipe.transformer.to(torch.float16)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
import PIL
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def main():
|
| 62 |
+
print("Loading dataset...")
|
| 63 |
+
parti_prompts = load_dataset("nateraw/parti-prompts", split="train")
|
| 64 |
+
|
| 65 |
+
print("Loading pipeline...")
|
| 66 |
+
seed = 0
|
| 67 |
+
|
| 68 |
+
device = "cuda"
|
| 69 |
+
torch.manual_seed(0)
|
| 70 |
+
|
| 71 |
+
ckpt_id = "openMUSE/muse-512"
|
| 72 |
+
|
| 73 |
+
scale = 10
|
| 74 |
+
|
| 75 |
+
print("Running inference...")
|
| 76 |
+
main_dict = {}
|
| 77 |
+
for i in range(len(parti_prompts)):
|
| 78 |
+
sample = parti_prompts[i]
|
| 79 |
+
prompt = sample["Prompt"]
|
| 80 |
+
|
| 81 |
+
image = pipe(
|
| 82 |
+
prompt,
|
| 83 |
+
timesteps=16,
|
| 84 |
+
negative_text=None,
|
| 85 |
+
guidance_scale=scale,
|
| 86 |
+
temperature=(2, 0),
|
| 87 |
+
orig_size=(512, 512),
|
| 88 |
+
crop_coords=(0, 0),
|
| 89 |
+
aesthetic_score=6,
|
| 90 |
+
use_fp16=device == "cuda",
|
| 91 |
+
transformer_seq_len=1024,
|
| 92 |
+
use_tqdm=False,
|
| 93 |
+
)[0]
|
| 94 |
+
|
| 95 |
+
image = image.resize((256, 256), resample=PIL.Image.Resampling.LANCZOS)
|
| 96 |
+
img_path = f"/home/patrick/muse_images/muse_512_{i}.png"
|
| 97 |
+
image.save(img_path)
|
| 98 |
+
main_dict.update(
|
| 99 |
+
{
|
| 100 |
+
prompt: {
|
| 101 |
+
"img_path": img_path,
|
| 102 |
+
"Category": sample["Category"],
|
| 103 |
+
"Challenge": sample["Challenge"],
|
| 104 |
+
"Note": sample["Note"],
|
| 105 |
+
"model_name": ckpt_id,
|
| 106 |
+
"seed": seed,
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
def generation_fn():
|
| 112 |
+
for prompt in main_dict:
|
| 113 |
+
prompt_entry = main_dict[prompt]
|
| 114 |
+
yield {
|
| 115 |
+
"Prompt": prompt,
|
| 116 |
+
"Category": prompt_entry["Category"],
|
| 117 |
+
"Challenge": prompt_entry["Challenge"],
|
| 118 |
+
"Note": prompt_entry["Note"],
|
| 119 |
+
"images": {"path": prompt_entry["img_path"]},
|
| 120 |
+
"model_name": prompt_entry["model_name"],
|
| 121 |
+
"seed": prompt_entry["seed"],
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
print("Preparing HF dataset...")
|
| 125 |
+
ds = Dataset.from_generator(
|
| 126 |
+
generation_fn,
|
| 127 |
+
features=Features(
|
| 128 |
+
Prompt=Value("string"),
|
| 129 |
+
Category=Value("string"),
|
| 130 |
+
Challenge=Value("string"),
|
| 131 |
+
Note=Value("string"),
|
| 132 |
+
images=ImageFeature(),
|
| 133 |
+
model_name=Value("string"),
|
| 134 |
+
seed=Value("int64"),
|
| 135 |
+
),
|
| 136 |
+
)
|
| 137 |
+
ds_id = "diffusers-parti-prompts/muse512"
|
| 138 |
+
ds.push_to_hub(ds_id)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
if __name__ == "__main__":
|
| 142 |
+
main()
|
| 143 |
+
```
|