Spaces:
Running
on
Zero
Running
on
Zero
Update stf_utils.py
Browse files- stf_utils.py +27 -11
stf_utils.py
CHANGED
@@ -11,6 +11,8 @@ import imageio
|
|
11 |
import numpy as np
|
12 |
from rich.progress import track
|
13 |
from tqdm import tqdm
|
|
|
|
|
14 |
|
15 |
import stf_alternative
|
16 |
|
@@ -75,20 +77,32 @@ class STFPipeline:
|
|
75 |
config_path: str = "front_config.json",
|
76 |
checkpoint_path: str = "089.pth",
|
77 |
#root_path: str = "works"
|
78 |
-
root_path: str = "/tmp/works"
|
|
|
79 |
|
80 |
):
|
81 |
#os.makedirs(root_path, exist_ok=True)
|
82 |
-
|
83 |
|
84 |
-
import zipfile
|
85 |
-
dir_zip='/tmp/works/preprocess/nasilhong_f_v1_front/crop_video_front_one_piece_dress_nodded_cut.zip'
|
86 |
-
dir_target='/tmp/works/preprocess/nasilhong_f_v1_front/'
|
87 |
-
zipfile.ZipFile(dir_zip, 'r').extractall(dir_target)
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
|
94 |
self.config_path = os.path.join(stf_path, config_path)
|
@@ -173,7 +187,6 @@ class STFPipeline:
|
|
173 |
)
|
174 |
for idx, (it, chunk) in enumerate(gen_infer, pivot):
|
175 |
frame = next(reader)
|
176 |
-
print('frame=', frame.shape, frame[:10])
|
177 |
composed = self.template.compose(idx, frame, it)
|
178 |
frame_name = f"{idx}".zfill(5)+".jpg"
|
179 |
results.append(it['pred'])
|
@@ -183,5 +196,8 @@ class STFPipeline:
|
|
183 |
|
184 |
print('STFPipeline execute 3')
|
185 |
images2video(results, save_path)
|
|
|
|
|
|
|
186 |
|
187 |
-
return save_path
|
|
|
11 |
import numpy as np
|
12 |
from rich.progress import track
|
13 |
from tqdm import tqdm
|
14 |
+
import zipfile
|
15 |
+
import shutil
|
16 |
|
17 |
import stf_alternative
|
18 |
|
|
|
77 |
config_path: str = "front_config.json",
|
78 |
checkpoint_path: str = "089.pth",
|
79 |
#root_path: str = "works"
|
80 |
+
root_path: str = "/tmp/works",
|
81 |
+
female_video: bool=True
|
82 |
|
83 |
):
|
84 |
#os.makedirs(root_path, exist_ok=True)
|
85 |
+
shutil.copytree('/home/user/app/stf/works', '/tmp/works', dirs_exist_ok=True)
|
86 |
|
|
|
|
|
|
|
|
|
87 |
|
88 |
+
|
89 |
+
if female_video:
|
90 |
+
dir_zip= os.path.join(root_path, 'preprocess/nasilhong_f_v1_front/crop_video_front_one_piece_dress_nodded_cut.zip')
|
91 |
+
dir_target=os.path.join(root_path,'preprocess/nasilhong_f_v1_front/')
|
92 |
+
zipfile.ZipFile(dir_zip, 'r').extractall(dir_target)
|
93 |
+
|
94 |
+
dir_zip=os.path.join(root_path,'preprocess/nasilhong_f_v1_front/front_one_piece_dress_nodded_cut.zip')
|
95 |
+
dir_target=os.path.join(root_path,'preprocess/nasilhong_f_v1_front/')
|
96 |
+
zipfile.ZipFile(dir_zip, 'r').extractall(dir_target)
|
97 |
+
else:
|
98 |
+
dir_zip= os.path.join(root_path, 'preprocess/Ian_v3_front/crop_video_Cam2_2309071202_0012_Natural_Looped.zip')
|
99 |
+
dir_target=os.path.join(root_path,'preprocess/Ian_v3_front/')
|
100 |
+
zipfile.ZipFile(dir_zip, 'r').extractall(dir_target)
|
101 |
+
|
102 |
+
dir_zip=os.path.join(root_path,'preprocess/Ian_v3_front/Cam2_2309071202_0012_Natural_Looped.zip')
|
103 |
+
dir_target=os.path.join(root_path,'preprocess/Ian_v3_front/')
|
104 |
+
zipfile.ZipFile(dir_zip, 'r').extractall(dir_target)
|
105 |
+
|
106 |
|
107 |
|
108 |
self.config_path = os.path.join(stf_path, config_path)
|
|
|
187 |
)
|
188 |
for idx, (it, chunk) in enumerate(gen_infer, pivot):
|
189 |
frame = next(reader)
|
|
|
190 |
composed = self.template.compose(idx, frame, it)
|
191 |
frame_name = f"{idx}".zfill(5)+".jpg"
|
192 |
results.append(it['pred'])
|
|
|
196 |
|
197 |
print('STFPipeline execute 3')
|
198 |
images2video(results, save_path)
|
199 |
+
|
200 |
+
save_path_aud = save_path.replace('.mp4', '_aud.mp4')
|
201 |
+
merge_audio_video(save_path, audio, save_path_aud)
|
202 |
|
203 |
+
return save_path_aud #save_path
|