-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
181 lines (120 loc) · 5.49 KB
/
main.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import numpy as np
import os
import time
import model.modelwrapper as Model
import random
import copy
import json
from GraphicCodeColection.mesh_sampling import generate_transform_matrices, generate_neighborhood, available_psbody
from GraphicCodeColection.loader import Loader
argv = os.sys.argv
if argv[1] in ["test", "train", 'summary']:
mode = argv[1]
else :
mode = "train"
############################################################################
# SETTINGS and ARGUMENTS.
############################################################################
#common sets
name="test_model_2020_3sd-reiqwen"
name="vae_good_vae_01"
#loader sets
noise_type = "plain"
data_path = "./processed_dataset/plain/bareteeth"
test_size = 10
loader = Loader(common_load_dir_name=data_path,
noise_type= noise_type,
test_size=test_size)
ref = loader.get_reference()
# neighbor, _, _ = generate_neighborhood(ref.v, ref.f)
print(mode, "what is mode ")
#Encoder Type :
model_params = dict()
model_params['name'] = name
model_params['random_seed'] = 30000
model_params['batch_size'] = 2
model_params['kernel_size'] = 8
model_params['num_epoch'] = 200
# model_params['F'] = [16, 32]#, 64, 96, 128] ### input_shape [ hidden_layer_output_shape1 ... ]
model_params['F'] = [16,32, 64]#, 128]#, 64, 96]#, 128] ### input_shape [ hidden_layer_output_shape1 ... ]
model_params['use_latent'] = True
model_params['latent_size'] = model_params['F'][-1]
model_params['F_0'] = loader.get_train_shape()[-1]
# model_params['activation'] = "leakyrelu"
# model_params['activation'] = "tanh"
model_params['activation'] = "relu"
model_params['face'] = ref.f
# model_params['kernel_initializer'] = "xavier_normal_initializer"
# model_params['kernel_initializer'] = "xavier_uniform_initializer"
model_params['kernel_initializer'] = "truncated_normal_initializer"
# model_params['kernel_initializer'] = "random_normal_initializer"
# model_params['kernel_initializer'] = "random_uniform_initializer"
# A and adj is essentially same. but The expression is different.
if available_psbody :
_,A,D,U,neighbor = generate_transform_matrices(ref.v,ref.f,[4]*len(model_params['F']))
# A, D, U is Same Length.
A = list(map(lambda x:x.astype('float32'), A))
D = list(map(lambda x:x.astype('float32'), D))
U = list(map(lambda x:x.astype('float32'), U))
print("A", len(A))
print("U", len(U))
print("D", len(D))
A=A[0]
A.data = A.data/A.data
A = [A]
model_params['A'] = A # basically (5023, 5023) values is all 1,0 or 2.
model_params['ds_D'] = D
model_params['ds_U'] = U
else:
neighbor = generate_neighborhood(ref.v, ref.f)
model_params['adj'] = neighbor # neighbor is basically (5023, 32)
model_params['checkpoint_save_path'] =os.path.join('./checkpoints/', model_params['name'])
model_params['tensorboard_path'] = os.path.join('./summaries/',model_params['name'])
############################################################################
# CONFIGURATION
############################################################################
model = Model.ModelWrapper(**model_params)
############################################################################
# TRAIN & PREDICT & SUMMARY
############################################################################
if mode == "train":
datadict = loader.get_train_data()
inputs = datadict['input']
labels = datadict['labels']
inputs = loader.get_data_normalize2(inputs)
labels = loader.get_data_normalize2(labels)
# loader.save_ply(np.expand_dims(loader.label_facedata.std, axis=0), name="pred", path="./test/"+"file")
# loader.save_ply(np.expand_dims(loader.label_facedata.mean, axis=0), name="pred", path="./test/"+"test")
# print("inputs", inputs)
# print("inputs", np.max(inputs), np.min(inputs))
model.train(inputs, labels)
elif mode == "test":
# print("test mode")
# datadict = loader.get_test_data()
# inputs = datadict['input'][:test_size]
# labels = datadict['labels'][:test_size]
datadict = loader.get_train_data()
inputs = datadict['input'][:test_size]
labels = datadict['labels'][:test_size]
# print(np.max(inputs))
inputs = loader.get_data_normalize2(inputs)
labels = loader.get_data_normalize2(labels)
print(np.max(inputs))
# labels = loader.get_data_normalize(labels)
pred, loss = model.predict(inputs=inputs,labels=labels, batch_size=2)
print("pred losses loss : ", loss)
# loader.save_ply(pred, name="pred", path="./conv_ply/"+name)
# loader.save_ply(inputs, name = "test",path="./conv_ply/"+name)
# loader.save_ply(labels, name = "orig",path="./conv_ply/"+name)
loader.save_ply(loader.get_data_denormalize2(pred), name="pred", path="./conv_ply/"+name)
loader.save_ply(loader.get_data_denormalize2(inputs), name = "test",path="./conv_ply/"+name)
loader.save_ply(loader.get_data_denormalize2(labels), name = "orig",path="./conv_ply/"+name)
model.summary()
elif mode == "summary":
datadict = loader.get_train_data()
inputs = datadict['input'][:1]
labels = datadict['labels'][:1]
inputs = loader.get_data_normalize(inputs)
# labels = loader.get_data_normalize(labels)
pred, loss = model.predict(inputs=inputs,labels=labels, batch_size=1)
model.see_all_values()