1 定义一个.sh文件
设置好自己的路径
2 定义好运行的.py文件(只需更改灰色部分即可,其他照抄)
源文件
test_t2i_bliplist.sh
export SAVE_DIR="../test-output/t2i/"
export BLIP_TXT="../blip.txt"
python ../test_t2i_bliplist.py \
--save_dir=$SAVE_DIR \
--blip_txt=$BLIP_TXT
test_t2i_bliplist.py
import torch
from diffusers import StableDiffusionPipeline
import argparse
import os
import pdb
def parse_args():
parser = argparse.ArgumentParser(description="Simple example of a testing script.")
parser.add_argument(
"--save_dir",
type=str,
default=None,
required=True,
help="Path to save pic",
)
parser.add_argument(
"--blip_txt",
type=str,
default=None,
required=True,
help="lots of prompts",
)
args = parser.parse_args()
return args
args = parse_args()
if args.save_dir is not None:
os.makedirs(args.save_dir, exist_ok=True)
model_id = "/share/graphics_ai/diffusers_models/chahua/"
# pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
# pipe = pipe.to("cuda")
num = 0
blip_list=['a women in the road, 4k', 'a women in the forest, 4k']
print('1 args.save_dir', args.save_dir)
print('2 args.blip_txt', args.blip_txt)
blip=open(args.blip_txt,"r")
lines=blip.readlines()
for line in lines:
print('---', line) #
pdb.set_trace()
for prompt in blip_list:
# prompt = "a women in the forest, 4k,"
image = pipe(prompt).images[0]
image.save(args.save_dir+str(num)+".jpg")
num = num + 1
# image.save("./test-output/t2i/apple.jpg")