amildravid4292 commited on
Commit
c017bd8
·
verified ·
1 Parent(s): e17e5ee

Delete inversion

Browse files
inversion/.DS_Store DELETED
Binary file (6.15 kB)
 
inversion/inversion_ood.ipynb DELETED
The diff for this file is too large to render. See raw diff
 
inversion/inversion_real.ipynb DELETED
The diff for this file is too large to render. See raw diff
 
inversion/invert.py DELETED
@@ -1,87 +0,0 @@
1
- import sys
2
- import os
3
- sys.path.append(os.path.abspath(os.path.join("", "..")))
4
- import torch
5
- import torchvision
6
- import warnings
7
- warnings.filterwarnings("ignore")
8
- from PIL import Image
9
- from lora_w2w import LoRAw2w
10
- from utils import load_models, inference, save_model_w2w, save_model_for_diffusers
11
- from inversion import invert
12
- import argparse
13
-
14
-
15
- def main():
16
- parser = argparse.ArgumentParser()
17
- parser.add_argument("--device", default="cuda:0", type=str)
18
- parser.add_argument("--mean_path", default="/files/mean.pt", type=str, help="Path to file with parameter means")
19
- parser.add_argument("--std_path", default="/files/std.pt", type=str, help="Path to file with parameter standard deviations.")
20
- parser.add_argument("--v_path", default="/files/V.pt", type=str, help="Path to V orthogonal projection/unprojection matrix.")
21
- parser.add_argument("--dim_path", default="/files/weight_dimensions.pt", type=str, help="Path to file with dimensions of LoRA layers. Used for saving in Diffusers pipeline format.")
22
- parser.add_argument("--imfolder", default="/inversion/images/real_image/real/", type=str, help="Path to folder containing image.")
23
- parser.add_argument("--mask_path", default=None, type=str, help="Path to mask file.")
24
- parser.add_argument("--epochs", default=400, type=int)
25
- parser.add_argument("--lr", default= 1e-1, type=float)
26
- parser.add_argument("--weight_decay", default= 1e-10, type=float)
27
- parser.add_argument("--dim", default= 10000, type=int, help="Number of principal component coefficients to optimize.")
28
- parser.add_argument("--diffusers_format", default=False, action="store_true", help="Whether to save in mode that can be loaded in Diffusers pipeline")
29
- parser.add_argument("--save_name", default="/files/inversion1.pt", type=str, help="Output path + filename.")
30
-
31
-
32
-
33
- ### variables
34
- args = parser.parse_args()
35
- device = args.device
36
- mean_path = args.mean_path
37
- std_path = args.std_path
38
- v_path = args.v_path
39
- dim_path = args.dim_path
40
- imfolder = args.imfolder
41
- mask_path = args.mask_path
42
- epochs = args.epochs
43
- lr = args.lr
44
- weight_decay = args.weight_decay
45
- dim = args.dim
46
- diffusers_format = args.diffusers_format
47
- save_name = args.save_name
48
-
49
-
50
- ### load models
51
- unet, vae, text_encoder, tokenizer, noise_scheduler = load_models(device)
52
-
53
- ### load files
54
- mean = torch.load(mean_path).bfloat16().to(device)
55
- std = torch.load(std_path).bfloat16().to(device)
56
- v = torch.load(v_path).bfloat16().to(device)
57
- weight_dimensions = torch.load(dim_path)
58
-
59
- ### initialize network
60
-
61
- proj = torch.zeros(1,dim).bfloat16().to(device)
62
- network = LoRAw2w( proj, mean, std, v[:,:dim],
63
- unet,
64
- rank=1,
65
- multiplier=1.0,
66
- alpha=27.0,
67
- train_method="xattn-strict"
68
- ).to(device, torch.bfloat16)
69
- ### run inversion
70
- network = invert(network=network, unet=unet, vae=vae,
71
- text_encoder=text_encoder, tokenizer=tokenizer,
72
- prompt = "sks person", noise_scheduler = noise_scheduler, epochs=epochs,
73
- image_path = imfolder, mask_path = mask_path, device = device)
74
-
75
-
76
- ### save model
77
-
78
- if diffusers_format:
79
- save_model_for_diffusers(network,std, mean, v, weight_dimensions,
80
- path=save_name)
81
- else:
82
- save_model_w2w(network, path=save_name)
83
-
84
-
85
-
86
- if __name__ == "__main__":
87
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inversion/run_inversion.sh DELETED
@@ -1,22 +0,0 @@
1
- python inversion/invert.py \
2
- --device="cuda:0" \
3
- --mean_path="files/mean.pt" \
4
- --std_path="files/std.pt" \
5
- --v_path="files/V.pt" \
6
- --std_path="files/std.pt" \
7
- --dim_path="files/weight_dimensions.pt" \
8
- --imfolder="inversion/images/real_image/real/" \
9
- --mask_path="inversion/images/real_image/mask.png" \
10
- --epochs=400 \
11
- --lr=1e-1 \
12
- --weight_decay=1e-10 \
13
- --dim=10000 \
14
- --save_name="files/real_inversion1.pt"
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-