Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,881 Bytes
9e2567f cf92dec 9e2567f cf92dec 9e2567f cf92dec 9e2567f |
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 |
import subprocess
import sys
import os
import tyro
from pixel3dmm import env_paths
def run_and_check(cmd, cwd=None):
"""
Run a command (list of args) in an optional cwd.
Raises CalledProcessError (with stdout/stderr) on failure.
"""
print(f"> {' '.join(cmd)} (in {cwd or os.getcwd()})")
result = subprocess.run(
cmd,
cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True, # will raise on non-zero exit
)
print(result.stdout) # print normal output
return result
def main(video_or_images_path: str):
# derive video name
if os.path.isdir(video_or_images_path):
vid_name = os.path.basename(video_or_images_path)
else:
vid_name, _ = os.path.splitext(os.path.basename(video_or_images_path))
try:
# cropping
run_and_check(
["python", "run_cropping.py", "--video_or_images_path", video_or_images_path],
cwd=os.path.join(env_paths.CODE_BASE, "scripts")
)
# MICA preprocessing
run_and_check(
["python", "demo.py", "-video_name", vid_name],
cwd=os.path.join(env_paths.CODE_BASE, "src", "pixel3dmm", "preprocessing", "MICA")
)
# face segmentation
run_and_check(
["python", "run_facer_segmentation.py", "--video_name", vid_name],
cwd=os.path.join(env_paths.CODE_BASE, "scripts")
)
except subprocess.CalledProcessError as e:
# Print the error, including stdout/stderr
print(f"ERROR: Command {e.cmd!r} exited with {e.returncode}", file=sys.stderr)
print("---- STDOUT ----", file=sys.stderr)
print(e.stdout, file=sys.stderr)
print("---- STDERR ----", file=sys.stderr)
sys.exit(e.returncode)
if __name__ == "__main__":
tyro.cli(main)
|