-
Notifications
You must be signed in to change notification settings - Fork 154
/
run_opt_rgbd.sh
248 lines (202 loc) · 7.12 KB
/
run_opt_rgbd.sh
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
GPU_NO=0;
is_bfm="False"
# # constants
basic_path=$(pwd)/3DMM/files/;
resources_path=$(pwd)/resources/;
uv_base="$basic_path/AI-NEXT-Albedo-Global.mat"
uv_regional_pyramid_base="$basic_path/AI-NEXT-AlbedoNormal-RPB/"
if [ $is_bfm == "False" ];then
shape_exp_bases="$basic_path/AI-NEXT-Shape.mat"
else
shape_exp_bases="$resources_path/BFM2009_Model.mat"
fi
vggpath="$resources_path/vgg-face.mat"
info_for_add_head="$resources_path/info_for_add_head.npy"
pb_path=$resources_path/PB/
# # data directories
is_only_four_frame="False"
ROOT_DIR=$(pwd)/test_data/RGBD/test1/;
img_dir="$ROOT_DIR"
########################################################
echo "prepare datas";
prefit_dir="$ROOT_DIR/prefit"
prepare_dir="$ROOT_DIR/prepare"
cd ./data_prepare
python -u run_data_preparation.py \
--GPU_NO=${GPU_NO} \
--mode='test_RGBD' \
--pb_path=${pb_path} \
--img_dir=${img_dir}/ \
--out_dir=${prepare_dir}
if [ "$?" -ne 0 ]; then echo "data prepare failed"; exit 1; fi
cd ..
########################################################
cd ./optimization/rgbd
echo "start RGBD opt process";
echo "step 0: load datas";
python -u step0_prepare_frontend_data.py \
--capture_dir=$img_dir \
--prepare_dir=${prepare_dir}
if [ "$?" -ne 0 ]; then echo "(step 0) load datas failed"; exit 1; fi
echo "step 1: choose frames : mid-left-right-up";
if [ $is_only_four_frame == "False" ];then
python -u step1A_choose_frames.py \
--prepare_dir=${prepare_dir}/ \
--prefit=${prefit_dir}/
else
python -u step1B_only4_choose_frames.py \
--prepare_dir=${prepare_dir}/ \
-prefit=${prefit_dir}/
fi
if [ "$?" -ne 0 ]; then echo "(step 1) choose frames failed"; exit 1; fi
echo "step 2: sparse fusion ";
python -u step2_sparse_fusion.py \
--is_bfm=${is_bfm} \
--prefit=${prefit_dir}/
if [ "$?" -ne 0 ]; then echo "(step 2) sparse fusion failed"; exit 1; fi
echo "step 3: prefit shape ";
python -u step3_prefit_shape.py \
--GPU_NO=${GPU_NO} \
--is_bfm=${is_bfm} \
--prefit=${prefit_dir}/ \
--modle_path=${resources_path} \
--basis3dmm_path=${shape_exp_bases}
if [ "$?" -ne 0 ]; then echo "(step 3) prefit shape failed"; exit 1; fi
echo "step 4: prefit Albedo_Global uv ";
if [ $is_bfm == "False" ];then
python -u step4A_prefit_Albedo_Global.py \
--GPU_NO=${GPU_NO} \
--is_bfm=${is_bfm} \
--basis3dmm_path=${shape_exp_bases} \
--uv_path=${uv_base} \
--resources_path=${resources_path} \
--output_dir=${prefit_dir}/
else
python -u step4B_prefit_bfm_rgb.py \
--GPU_NO=${GPU_NO} \
--num_of_img=4 \
--is_bfm=${is_bfm} \
--basis3dmm_path=${shape_exp_bases} \
--uv_path=${uv_base} \
--vggpath=${vggpath} \
--prefit_dir=${prefit_dir} \
--prepare_dir=${prepare_dir} \
--summary_dir=${prefit_dir}/sum_prefit_bfm_tex/
fi
if [ "$?" -ne 0 ]; then echo "(step 4) prefit uv failed"; exit 1; fi
echo "step 5: start RGBD opt ";
if [ $is_bfm == "False" ];then
shape_out_dir=${ROOT_DIR}/our_opt_RGBD
else
shape_out_dir=${ROOT_DIR}/bfm_opt_RGBD
fi
# constants
log_step=10
learning_rate=0.05
lr_decay_step=10
lr_decay_rate=0.9
photo_weight=100
gray_photo_weight=80
reg_shape_weight=0.4
reg_tex_weight=0.0001
depth_weight=1000
id_weight=1.8
real_86pt_lmk3d_weight=0.01
lmk_struct_weight=0
train_step=100
is_fixed_pose="False"
is_add_head_mirrow="False"
is_add_head_male="True"
python step5_run_RGBD_opt.py \
--GPU_NO=${GPU_NO} \
--is_bfm=${is_bfm} \
--basis3dmm_path=${shape_exp_bases} \
--uv_path=${uv_base} \
--vggpath=${vggpath} \
--info_for_add_head=${info_for_add_head} \
--prefit_dir=${prefit_dir} \
--prepare_dir=${prepare_dir} \
--log_step=${log_step} \
--train_step=${train_step} \
--learning_rate=${learning_rate} \
--lr_decay_step=${lr_decay_step} \
--lr_decay_rate=${lr_decay_rate} \
--photo_weight=${photo_weight} \
--gray_photo_weight=${gray_photo_weight} \
--depth_weight=${depth_weight} \
--id_weight=${id_weight} \
--reg_shape_weight=${reg_shape_weight} \
--reg_tex_weight=${reg_tex_weight} \
--real_86pt_lmk3d_weight=${real_86pt_lmk3d_weight} \
--lmk_struct_weight=${lmk_struct_weight} \
--num_of_img=4 \
--fixed_pose=${is_fixed_pose} \
--is_add_head_mirrow=${is_add_head_mirrow} \
--is_add_head_male=${is_add_head_male} \
--out_dir=${shape_out_dir} \
--summary_dir=${shape_out_dir}/summary \
if [ "$?" -ne 0 ]; then echo "(step 5) RGBD opt failed"; exit 1; fi
cd ../..
########################################################
if [ $is_bfm == "False" ];then
echo "start generate HD texture";
cd ./texture
echo "step0: start unwrap";
CUDA_VISIBLE_DEVICES=${GPU_NO} python -u step0_unwrapper.py \
--basis3dmm_path=${shape_exp_bases} \
--uv_path=${uv_base} \
--uv_size=512 \
--is_mult_view=True \
--is_orig_img=False \
--input_dir=${shape_out_dir} \
--output_dir=${ROOT_DIR}/unwrap
if [ "$?" -ne 0 ]; then echo "unwrap failed"; exit 1; fi
echo "step1: start fit AlbedoNormal_RPB";
CUDA_VISIBLE_DEVICES=${GPU_NO} python -u step1_fit_AlbedoNormal_RPB.py \
--basis3dmm_path=${shape_exp_bases} \
--uv_path=${uv_regional_pyramid_base} \
--write_graph=False \
--data_dir=${ROOT_DIR}/unwrap \
--out_dir=${ROOT_DIR}/fit_unwrap \
--uv_tv_weight=0.1 \
--uv_reg_tex_weight=0.001 \
--learning_rate=0.1 \
--train_step=200
if [ "$?" -ne 0 ]; then echo "fit UV failed"; exit 1; fi
echo "step2: generate tex";
CUDA_VISIBLE_DEVICES=${GPU_NO} python -u step2_pix2pix.py --mode texture --func test --pb_path ${pb_path}/pix2pix_tex.pb \
--input_dir=${ROOT_DIR}/fit_unwrap \
--output_dir=${ROOT_DIR}/pix2pix
if [ "$?" -ne 0 ]; then echo "generate tex failed"; exit 1; fi
echo "step2: generate norm";
CUDA_VISIBLE_DEVICES=${GPU_NO} python -u step2_pix2pix.py --mode normal --func test --pb_path ${pb_path}/pix2pix_norm.pb \
--input_dir=${ROOT_DIR}/fit_unwrap \
--output_dir=${ROOT_DIR}/pix2pix
if [ "$?" -ne 0 ]; then echo "generate norm failed"; exit 1; fi
FIT_DIR=$ROOT_DIR/fit_unwrap
PIX_DIR=$ROOT_DIR/pix2pix
UNWRAP_DIR=$ROOT_DIR/unwrap
OUT_DIR=$ROOT_DIR/pix2pix_convert
echo "step3: convert_texture_domain";
python -u step3_convert_texture_domain.py \
--input_fit_dir=$FIT_DIR \
--input_pix2pix_dir=$PIX_DIR \
--input_unwrap_dir=$UNWRAP_DIR \
--output_dir=$OUT_DIR
if [ "$?" -ne 0 ]; then echo "convert_texture_domain failed"; exit 1; fi
cd ..
fi
########################################################
echo "output results";
results_dir=$ROOT_DIR/results
mkdir -p $results_dir
if [ $is_bfm == "False" ];then
scp $(pwd)/test.mtl $results_dir/
scp ${shape_out_dir}/head* $results_dir/
scp $ROOT_DIR/pix2pix_convert/output_for_texture_tex_D.png $results_dir/albedo.png
scp $ROOT_DIR/pix2pix/out_for_texture_tex_N.png $results_dir/normal.png
else
scp ${shape_out_dir}/face* $results_dir/
fi
echo "finish";