Datasets:

ArXiv:
sd3_5_fine_sixcard / playground.py
yyyzzzzyyy's picture
Add files using upload-large-folder tool
4535b2e verified
raw
history blame
5.45 kB
from diffusers import DiffusionPipeline
import torch
import os
import pandas as pd
device = "cuda:1" # Specify the device to use, e.g., "cuda:0" or "cuda:1"
pipe = DiffusionPipeline.from_pretrained(
"playgroundai/playground-v2.5-1024px-aesthetic",
torch_dtype=torch.float16,
variant="fp16",
).to(device)
root_dir = "/DATA/DATA3/zhaoyu/T2I_model_SD35/diffusers/examples/dreambooth"
# #---------------------------------------------------------
# #-----------------------------------------------------------------------
# prompt_file = os.path.join(root_dir,"prompt.txt")
# with open(prompt_file, 'r') as f:
# prompts = [line.strip() for line in f]
# image_root_dir =root_dir
# save_dir= os.path.join(image_root_dir, "images_0_playground")
# os.makedirs(save_dir, exist_ok=True)
# cnt = 1
# prompts = prompts[cnt - 1:] # 截取的时候是包含当前这一项的,也就是包含cnt-1这一项
# #-----------------------------------------------------------------------
# for index,prompt in enumerate(prompts,start=cnt-1):
# image_name = f"fintune_2epoch_{index:06d}.png"
# save_path = os.path.join(save_dir, image_name)
# image = pipe(
# prompt,
# num_inference_steps=28,
# guidance_scale=3.5,
# generator=torch.Generator(device).manual_seed(42)
# ).images[0]
# image.save(save_path)
#---------------------------------------------------------
#-----------------------------------------------------------------------
# 设定路径
csv_file = os.path.join(root_dir,"data.csv")
df = pd.read_csv(csv_file)
prompts= df["prompt"]
prompts = prompts[:300]
image_root_dir =os.path.join(root_dir,"AGIQA-300")
save_dir= os.path.join(image_root_dir, "images_0_playground")
os.makedirs(save_dir, exist_ok=True)
cnt = 1
prompts = prompts[cnt - 1:] # 截取的时候是包含当前这一项的,也就是包含cnt-1这一项
#-----------------------------------------------------------------------
for index,prompt in enumerate(prompts,start=cnt-1):
image_name = f"fintune_2epoch_{index:06d}.png"
save_path = os.path.join(save_dir, image_name)
image = pipe(
prompt,
num_inference_steps=28,
guidance_scale=3.5,
generator=torch.Generator(device).manual_seed(42)
).images[0]
image.save(save_path)
#---------------------------------------------------------
#-----------------------------------------------------------------------
# 设定路径
# 设定路径
csv_file = os.path.join(root_dir,"dataset/AGIQA-1K/AIGC_MOS_Zscore.csv")
df = pd.read_csv(csv_file)
prompts= df["Prompt"]
prompts = prompts[:720]
image_root_dir =os.path.join(root_dir,"AGIQA-1K")
save_dir= os.path.join(image_root_dir, "images_0_playground")
os.makedirs(save_dir, exist_ok=True)
cnt = 1
prompts = prompts[cnt - 1:] # 截取的时候是包含当前这一项的,也就是包含cnt-1这一项
#-----------------------------------------------------------------------
for index,prompt in enumerate(prompts,start=cnt-1):
image_name = f"fintune_2epoch_{index:06d}.png"
save_path = os.path.join(save_dir, image_name)
image = pipe(
prompt,
num_inference_steps=28,
guidance_scale=3.5,
generator=torch.Generator(device).manual_seed(42)
).images[0]
image.save(save_path)
#---------------------------------------------------------
#-----------------------------------------------------------------------
# 设定路径
prompt_file = os.path.join(root_dir,"dataset/genaibench/genai_prompts.txt")
with open(prompt_file, 'r') as f:
prompts = [line.strip() for line in f]
image_root_dir =os.path.join(root_dir,"genai_bench")
save_dir= os.path.join(image_root_dir, "images_0_playground")
os.makedirs(save_dir, exist_ok=True)
cnt = 1
prompts = prompts[cnt - 1:] # 截取的时候是包含当前这一项的,也就是包含cnt-1这一项
#-----------------------------------------------------------------------
for index,prompt in enumerate(prompts,start=cnt-1):
image_name = f"fintune_2epoch_{index:06d}.png"
save_path = os.path.join(save_dir, image_name)
image = pipe(
prompt,
num_inference_steps=28,
guidance_scale=3.5,
generator=torch.Generator(device).manual_seed(42)
).images[0]
image.save(save_path)
#---------------------------------------------------------
#-----------------------------------------------------------------------
# 设定路径
prompt_file = os.path.join(root_dir,"dataset/TIFA/tifa_prompts.txt")
with open(prompt_file, 'r') as f:
prompts = [line.strip() for line in f]
image_root_dir =os.path.join(root_dir,"TIFA")
save_dir= os.path.join(image_root_dir, "images_0_playground")
os.makedirs(save_dir, exist_ok=True)
cnt = 1
prompts = prompts[cnt - 1:] # 截取的时候是包含当前这一项的,也就是包含cnt-1这一项
#-----------------------------------------------------------------------
for index,prompt in enumerate(prompts,start=cnt-1):
image_name = f"fintune_2epoch_{index:06d}.png"
save_path = os.path.join(save_dir, image_name)
image = pipe(
prompt,
num_inference_steps=28,
guidance_scale=3.5,
generator=torch.Generator(device).manual_seed(42)
).images[0]
image.save(save_path)
#---------------------------------------------------------
#-----------------------------------------------------------------------