Spaces:
Running
Running
File size: 1,115 Bytes
8b44f58 | 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 | !pip install torch torchvision
!pip install diffusers
!pip install transformers
!pip install datasets
!pip install accelerate
!pip install pillow
!pip install matplotlib
!pip install scipy
!pip install pandas
!pip install torchmetrics
!pip install clean-fid
!pip install open_clip_torch
from datasets import load_dataset
dataset = load_dataset(
"jackyhate/text-to-image-2M",
split="train",
streaming=True
)
sample = next(iter(dataset))
print(sample)
import torch
from diffusers import AutoPipelineForText2Image
pipe = AutoPipelineForText2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=torch.float16
)
pipe.to("cuda")
prompt = sample["text"]
image = pipe(
prompt,
num_inference_steps=30,
guidance_scale=7.5
).images[0]
image.save("outputs/generated.png")
from torchmetrics.multimodal.clip_score import CLIPScore
metric = CLIPScore(model_name_or_path="openai/clip-vit-base-patch32")
score = metric(
image,
prompt
)
print(score)
from cleanfid import fid
score = fid.compute_fid(
"real_images",
"generated_images"
)
print(score) |