Views
No views yet
CUDA_VISIBLE_DEVICES=0 PYTHONPATH='./' python3 anysd/infer.py1import os
2from tqdm import tqdm
3from anysd.src.model import AnySDPipeline, choose_expert
4from anysd.train.valid_log import download_image
5from anysd.src.utils import choose_book, get_experts_dir
6
7if __name__ == "__main__":
8 expert_file_path = get_experts_dir(repo_id="WeiChow/AnySD")
9 book_dim, book = choose_book('all')
10 task_embs_checkpoints = expert_file_path + "task_embs.bin"
11 adapter_checkpoints = {
12 "global": expert_file_path + "global.bin",
13 "viewpoint": expert_file_path + "viewpoint.bin",
14 "visual_bbox": expert_file_path + "visual_bbox.bin",
15 "visual_depth": expert_file_path + "visual_dep.bin",
16 "visual_material_transfer": expert_file_path + "visual_mat.bin",
17 "visual_reference": expert_file_path + "visual_ref.bin",
18 "visual_scribble": expert_file_path + "visual_scr.bin",
19 "visual_segment": expert_file_path + "visual_seg.bin",
20 "visual_sketch": expert_file_path + "visual_ske.bin",
21 }
22
23 pipeline = AnySDPipeline(adapters_list=adapter_checkpoints, task_embs_checkpoints=task_embs_checkpoints)
24
25 os.makedirs('./assets/anysd-test/', exist_ok=True)
26 case = [
27 {
28 "edit": "Put on a pair of sunglasses",
29 "edit_type": 'general',
30 "image_file": "./assets/woman.jpg"
31 },
32 {
33 "edit": "Make her a wizard",
34 "edit_type": 'general',
35 "image_file": "./assets/woman.jpg"
36 }
37 ]
38
39 for index, item in enumerate(tqdm(case)):
40 mode = choose_expert(mode=item["edit_type"])
41 if mode == 'general':
42 images = pipeline(
43 prompt=item['edit'],
44 original_image=download_image(item['image_file']),
45 guidance_scale=3,
46 num_inference_steps=100,
47 original_image_guidance_scale=3,
48 adapter_name="general",
49 )[0]
50 else:
51 images = pipeline(
52 prompt=item['edit'],
53 reference_image=download_image(item['refence_image_file']) if ('refence_image_file' in item.keys() and item['refence_image_file'] is not None) else None,
54 original_image=download_image(item['image_file']),
55 guidance_scale=1.5,
56 num_inference_steps=100,
57 original_image_guidance_scale=2,
58 reference_image_guidance_scale=0.8,
59 adapter_name=mode,
60 e_code=book[item["edit_type"]],
61 )[0]
62
63 images.save(f"./assets/anysd-test/{index}.jpg")1@article{yu2024anyedit,
2 title={AnyEdit: Mastering Unified High-Quality Image Editing for Any Idea},
3 author={Yu, Qifan and Chow, Wei and Yue, Zhongqi and Pan, Kaihang and Wu, Yang and Wan, Xiaoyang and Li, Juncheng and Tang, Siliang and Zhang, Hanwang and Zhuang, Yueting},
4 journal={arXiv preprint arXiv:2411.15738},
5 year={2024}
6}