-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis_clean.py
93 lines (71 loc) · 1.63 KB
/
analysis_clean.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import argparse
from torch_ksvd_2d import TorchApproximateKSVD
import torch
import numpy as np
def parse_args():
parser = argparse.ArgumentParser(description="Generate heatmap")
parser.add_argument(
"--sp",
type=int,
default=0,
help="Example index",
)
parser.add_argument(
"--basis",
type=int,
default=0,
help="Example index",
)
parser.add_argument(
"--d_path",
type=str,
default=None,
help="Example index",
)
parser.add_argument(
"--c_path",
type=str,
default=None,
help="Example index",
)
parser.add_argument(
"--w_path",
type=str,
default=0,
help="Example index",
required=True
)
parser.add_argument(
"--save_name",
type=str,
default="save",
required=True
)
return parser.parse_args()
args = parse_args()
device = "cuda:0"
W = torch.from_numpy(np.load(args.w_path)).to(torch.float32).to(device)
print(W.shape)
sp,head_size = args.sp, W.shape[2]
C, D = None, None
c_path, d_path = args.c_path, args.d_path
if (c_path is not None):
C = torch.from_numpy(np.load(c_path)).to(device)
if (d_path is not None):
D = torch.from_numpy(np.load(d_path)).to(device)
num_comp = args.basis
ksvd = TorchApproximateKSVD(
num_basis=num_comp,
max_iter=4,
coef_sparsity=sp,
name=args.save_name,
logger=None,
device=device,
shouldQ=False,
head_size=head_size,
)
ksvd.fit_external(
X = W,
D_init = D,
coefficients_init=C
)