Spaces:
Running
on
Zero
Running
on
Zero
Update scripts/run_preprocessing.py
Browse files- scripts/run_preprocessing.py +18 -30
scripts/run_preprocessing.py
CHANGED
@@ -1,54 +1,42 @@
|
|
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 |
-
|
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 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
try:
|
33 |
-
# cropping
|
34 |
run_and_check(
|
35 |
-
["
|
36 |
-
cwd=
|
37 |
)
|
38 |
-
# MICA preprocessing
|
39 |
run_and_check(
|
40 |
-
["
|
41 |
-
cwd=
|
42 |
)
|
43 |
-
# face segmentation
|
44 |
run_and_check(
|
45 |
-
["
|
46 |
-
cwd=
|
47 |
)
|
48 |
-
|
49 |
except subprocess.CalledProcessError as e:
|
50 |
-
|
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)
|
|
|
1 |
+
import subprocess, sys, os
|
|
|
|
|
2 |
import tyro
|
|
|
3 |
from pixel3dmm import env_paths
|
4 |
|
5 |
def run_and_check(cmd, cwd=None):
|
|
|
|
|
|
|
|
|
6 |
print(f"> {' '.join(cmd)} (in {cwd or os.getcwd()})")
|
7 |
+
# stream logs live
|
8 |
result = subprocess.run(
|
9 |
cmd,
|
10 |
cwd=cwd,
|
11 |
+
check=True,
|
|
|
|
|
|
|
12 |
)
|
|
|
13 |
return result
|
14 |
|
15 |
def main(video_or_images_path: str):
|
16 |
+
vid_name = (
|
17 |
+
os.path.basename(video_or_images_path)
|
18 |
+
if os.path.isdir(video_or_images_path)
|
19 |
+
else os.path.splitext(os.path.basename(video_or_images_path))[0]
|
20 |
+
)
|
21 |
+
|
22 |
+
SCRIPTS = os.path.join(env_paths.CODE_BASE, "scripts")
|
23 |
+
MICA = os.path.join(env_paths.CODE_BASE, "src", "pixel3dmm", "preprocessing", "MICA")
|
24 |
|
25 |
try:
|
|
|
26 |
run_and_check(
|
27 |
+
[sys.executable, "-u", "run_cropping.py", "--video_or_images_path", video_or_images_path],
|
28 |
+
cwd=SCRIPTS,
|
29 |
)
|
|
|
30 |
run_and_check(
|
31 |
+
[sys.executable, "-u", "demo.py", "-video_name", vid_name],
|
32 |
+
cwd=MICA,
|
33 |
)
|
|
|
34 |
run_and_check(
|
35 |
+
[sys.executable, "-u", "run_facer_segmentation.py", "--video_name", vid_name],
|
36 |
+
cwd=SCRIPTS,
|
37 |
)
|
|
|
38 |
except subprocess.CalledProcessError as e:
|
39 |
+
print(f"ERROR: {e.cmd!r} exited with {e.returncode}", file=sys.stderr)
|
|
|
40 |
print("---- STDOUT ----", file=sys.stderr)
|
41 |
print(e.stdout, file=sys.stderr)
|
42 |
print("---- STDERR ----", file=sys.stderr)
|