基础模型:
- SherryXTChen/LatentDiffusionDINOv2
数据集:
- timbrooks/instructpix2pix-clip-filtered
- SherryXTChen/InstructCLIP-InstructPix2Pix-Data
语言:
- en
许可证: apache-2.0
管道标签: 图像到图像
库名称: diffusers
标签:
- 模型中心混合
- pytorch模型中心混合
InstructCLIP: 通过对比学习自动优化数据提升指令引导图像编辑效果 (CVPR 2025)
本模型通过PytorchModelHubMixin集成推送至Hub。该模型基于论文Instruct-CLIP: 通过对比学习自动优化数据提升指令引导图像编辑效果。
Arxiv | 图像编辑模型 | 数据优化模型 | 数据集
功能展示
安装
pip install -r requirements.txt
编辑指令优化推理
from PIL import Image
import torch
from torchvision import transforms
from model import InstructCLIP
from utils import get_sd_components, normalize
parser = argparse.ArgumentParser(description="从图像对估计编辑指令的简单示例")
parser.add_argument(
"--pretrained_instructclip_name_or_path",
type=str,
default="SherryXTChen/Instruct-CLIP",
help=(
"instructclip预训练检查点"
),
)
parser.add_argument(
"--pretrained_model_name_or_path",
type=str,
default="runwayml/stable-diffusion-v1-5",
help=(
"sd预训练检查点"
),
)
parser.add_argument(
"--input_path",
type=str,
default="assets/1_input.jpg",
help=(
"输入图像路径"
)
)
parser.add_argument(
"--output_path",
type=str,
default="assets/1_output.jpg",
help=(
"输出图像路径"
)
)
args = parser.parse_args()
device = "cuda"
model = InstructCLIP.from_pretrained("SherryXTChen/Instruct-CLIP")
model = model.to(device).eval()
tokenizer, _, vae, _, _ = get_sd_components(args, device, torch.float32)
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(mean=[0.5], std=[0.5]),
])
image_list = [args.input_path, args.output_path]
image_list = [
transform(Image.open(f).resize((512, 512))).unsqueeze(0).to(device)
for f in image_list
]
with torch.no_grad():
image_list = [vae.encode(x).latent_dist.sample() * vae.config.scaling_factor for x in image_list]
zero_timesteps = torch.zeros_like(torch.tensor([0])).to(device)
img_feat = model.get_image_features(
inp=image_list[0], out=image_list[1], inp_t=zero_timesteps, out_t=zero_timesteps)
img_feat = normalize(img_feat)
pred_instruct_input_ids = model.text_decoder.infer(img_feat[:1])[0]
pred_instruct = tokenizer.decode(pred_instruct_input_ids, skip_special_tokens=True)
print(pred_instruct)
引用
@misc{chen2025instructclipimprovinginstructionguidedimage,
title={Instruct-CLIP: 通过对比学习自动优化数据提升指令引导图像编辑效果},
author={Sherry X. Chen and Misha Sra and Pradeep Sen},
year={2025},
eprint={2503.18406},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2503.18406},
}