Spaces:
Running
on
Zero
Running
on
Zero
Update scripts/run_preprocessing.py
Browse files- scripts/run_preprocessing.py +51 -16
scripts/run_preprocessing.py
CHANGED
@@ -1,23 +1,58 @@
|
|
|
|
|
|
1 |
import os
|
2 |
import tyro
|
3 |
|
4 |
from pixel3dmm import env_paths
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
if os.path.isdir(video_or_images_path):
|
10 |
-
vid_name =
|
11 |
else:
|
12 |
-
vid_name =
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
import sys
|
3 |
import os
|
4 |
import tyro
|
5 |
|
6 |
from pixel3dmm import env_paths
|
7 |
|
8 |
+
def run_and_check(cmd, cwd=None):
|
9 |
+
"""
|
10 |
+
Run a command (list of args) in an optional cwd.
|
11 |
+
Raises CalledProcessError (with stdout/stderr) on failure.
|
12 |
+
"""
|
13 |
+
print(f"> {' '.join(cmd)} (in {cwd or os.getcwd()})")
|
14 |
+
result = subprocess.run(
|
15 |
+
cmd,
|
16 |
+
cwd=cwd,
|
17 |
+
stdout=subprocess.PIPE,
|
18 |
+
stderr=subprocess.PIPE,
|
19 |
+
text=True,
|
20 |
+
check=True, # will raise on non-zero exit
|
21 |
+
)
|
22 |
+
print(result.stdout) # print normal output
|
23 |
+
return result
|
24 |
+
|
25 |
+
def main(video_or_images_path: str):
|
26 |
+
# derive video name
|
27 |
if os.path.isdir(video_or_images_path):
|
28 |
+
vid_name = os.path.basename(video_or_images_path)
|
29 |
else:
|
30 |
+
vid_name, _ = os.path.splitext(os.path.basename(video_or_images_path))
|
31 |
+
|
32 |
+
try:
|
33 |
+
# cropping
|
34 |
+
run_and_check(
|
35 |
+
["python", "run_cropping.py", "--video_or_images_path", video_or_images_path],
|
36 |
+
cwd=os.path.join(env_paths.CODE_BASE, "scripts")
|
37 |
+
)
|
38 |
+
# MICA preprocessing
|
39 |
+
run_and_check(
|
40 |
+
["python", "demo.py", "-video_name", vid_name],
|
41 |
+
cwd=os.path.join(env_paths.CODE_BASE, "src", "pixel3dmm", "preprocessing", "MICA")
|
42 |
+
)
|
43 |
+
# face segmentation
|
44 |
+
run_and_check(
|
45 |
+
["python", "run_facer_segmentation.py", "--video_name", vid_name],
|
46 |
+
cwd=os.path.join(env_paths.CODE_BASE, "scripts")
|
47 |
+
)
|
48 |
+
|
49 |
+
except subprocess.CalledProcessError as e:
|
50 |
+
# Print the error, including stdout/stderr
|
51 |
+
print(f"ERROR: Command {e.cmd!r} exited with {e.returncode}", file=sys.stderr)
|
52 |
+
print("---- STDOUT ----", file=sys.stderr)
|
53 |
+
print(e.stdout, file=sys.stderr)
|
54 |
+
print("---- STDERR ----", file=sys.stderr)
|
55 |
+
sys.exit(e.returncode)
|
56 |
+
|
57 |
+
if __name__ == "__main__":
|
58 |
+
tyro.cli(main)
|