Spaces:
Running
on
Zero
Running
on
Zero
| 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) | |