|
|
import torch |
|
|
from diffusers import FluxPipeline |
|
|
import os |
|
|
import pandas as pd |
|
|
|
|
|
device = "cuda:0" |
|
|
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16).to(device) |
|
|
|
|
|
root_dir = "/DATA/DATA3/zhaoyu/T2I_model_SD35/diffusers/examples/dreambooth" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, "image_0_flux_schnell") |
|
|
os.makedirs(save_dir, exist_ok=True) |
|
|
cnt = 1 |
|
|
prompts = prompts[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, |
|
|
guidance_scale=0.0, |
|
|
num_inference_steps=4, |
|
|
max_sequence_length=256, |
|
|
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, "image_0_flux_schnell") |
|
|
os.makedirs(save_dir, exist_ok=True) |
|
|
cnt = 1 |
|
|
prompts = prompts[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, |
|
|
guidance_scale=0.0, |
|
|
num_inference_steps=4, |
|
|
max_sequence_length=256, |
|
|
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, "image_0_flux_schnell") |
|
|
os.makedirs(save_dir, exist_ok=True) |
|
|
cnt = 1 |
|
|
prompts = prompts[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, |
|
|
guidance_scale=0.0, |
|
|
num_inference_steps=4, |
|
|
max_sequence_length=256, |
|
|
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, "image_0_flux_schnell") |
|
|
os.makedirs(save_dir, exist_ok=True) |
|
|
cnt = 1 |
|
|
prompts = prompts[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, |
|
|
guidance_scale=0.0, |
|
|
num_inference_steps=4, |
|
|
max_sequence_length=256, |
|
|
generator=torch.Generator(device).manual_seed(42) |
|
|
).images[0] |
|
|
image.save(save_path) |
|
|
|
|
|
|
|
|
|
|
|
|