|
| 1 | +import argparse |
| 2 | + |
| 3 | +from diffusers import UnCLIPImageVariationPipeline, UnCLIPPipeline |
| 4 | +from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection |
| 5 | + |
| 6 | + |
| 7 | +if __name__ == "__main__": |
| 8 | + parser = argparse.ArgumentParser() |
| 9 | + |
| 10 | + parser.add_argument("--dump_path", default=None, type=str, required=True, help="Path to the output model.") |
| 11 | + |
| 12 | + parser.add_argument( |
| 13 | + "--txt2img_unclip", |
| 14 | + default="kakaobrain/karlo-v1-alpha", |
| 15 | + type=str, |
| 16 | + required=False, |
| 17 | + help="The pretrained txt2img unclip.", |
| 18 | + ) |
| 19 | + |
| 20 | + args = parser.parse_args() |
| 21 | + |
| 22 | + txt2img = UnCLIPPipeline.from_pretrained(args.txt2img_unclip) |
| 23 | + |
| 24 | + feature_extractor = CLIPImageProcessor() |
| 25 | + image_encoder = CLIPVisionModelWithProjection.from_pretrained("openai/clip-vit-large-patch14") |
| 26 | + |
| 27 | + img2img = UnCLIPImageVariationPipeline( |
| 28 | + decoder=txt2img.decoder, |
| 29 | + text_encoder=txt2img.text_encoder, |
| 30 | + tokenizer=txt2img.tokenizer, |
| 31 | + text_proj=txt2img.text_proj, |
| 32 | + feature_extractor=feature_extractor, |
| 33 | + image_encoder=image_encoder, |
| 34 | + super_res_first=txt2img.super_res_first, |
| 35 | + super_res_last=txt2img.super_res_last, |
| 36 | + decoder_scheduler=txt2img.decoder_scheduler, |
| 37 | + super_res_scheduler=txt2img.super_res_scheduler, |
| 38 | + ) |
| 39 | + |
| 40 | + img2img.save_pretrained(args.dump_path) |
0 commit comments