From bd9401a6964d11f1abed02211667f7daf7c1ebdd Mon Sep 17 00:00:00 2001 From: mbukeRepo Date: Sat, 6 Jul 2024 13:13:39 +0200 Subject: [PATCH 1/4] chore: setup replicate deployment --- .dockerignore | 17 +++++++++++++++++ cog.yaml | 27 +++++++++++++++++++++++++++ predict.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 .dockerignore create mode 100644 cog.yaml create mode 100644 predict.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4522d57 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +# The .dockerignore file excludes files from the container build process. +# +# https://docs.docker.com/engine/reference/builder/#dockerignore-file + +# Exclude Git files +.git +.github +.gitignore + +# Exclude Python cache files +__pycache__ +.mypy_cache +.pytest_cache +.ruff_cache + +# Exclude Python virtual environment +/venv diff --git a/cog.yaml b/cog.yaml new file mode 100644 index 0000000..a02f5f1 --- /dev/null +++ b/cog.yaml @@ -0,0 +1,27 @@ +# Configuration for Cog ⚙️ +# Reference: https://cog.run/yaml + +build: + gpu: true + python_version: "3.11" + python_packages: + - "torch==2.3.0" + - "torchvision==0.18.0" + - "torchaudio==2.3.0" + - "numpy==1.26.4" + - "pyyaml==6.0.1" + - "opencv-python==4.10.0.84" + - "scipy==1.13.1" + - "imageio==2.34.2" + - "lmdb==1.4.1" + - "tqdm==4.66.4" + - "rich==13.7.1" + - "ffmpeg==1.4" + - "onnxruntime-gpu==1.18.0" + - "onnx==1.16.1" + - "scikit-image==0.24.0" + - "albumentations==1.4.10" + - "matplotlib==3.9.0" + - "imageio-ffmpeg==0.5.1" + - "tyro==0.8.5" +predict: "predict.py:Predictor" diff --git a/predict.py b/predict.py new file mode 100644 index 0000000..f0957b2 --- /dev/null +++ b/predict.py @@ -0,0 +1,29 @@ +from cog import BasePredictor, Input, Path + +from src.config.argument_config import ArgumentConfig +from src.config.inference_config import InferenceConfig +from src.config.crop_config import CropConfig +from src.live_portrait_pipeline import LivePortraitPipeline + + +class Predictor(BasePredictor): + def setup(self) -> None: + """Load the model into memory to make running multiple predictions efficient""" + self.live_portrait_pipeline = LivePortraitPipeline( + inference_cfg=InferenceConfig(), + crop_cfg=CropConfig() + ) + + def predict( + self, + image: Path = Input(description="Portrait image"), + driving_info: Path = Input( + description="driving video or template (.pkl format)" + ), + ) -> Path: + """Run a single prediction on the model""" + video_path, _ = self.live_portrait_pipeline.execute( + ArgumentConfig(source_image=image, driving_info=driving_info, output_dir="/tmp/") + ) + + return Path(video_path) From 0b303fc39cc23294109cefb874f55285398533d8 Mon Sep 17 00:00:00 2001 From: mbukeRepo Date: Sat, 6 Jul 2024 19:48:43 +0200 Subject: [PATCH 2/4] chore: integrate system packages --- cog.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cog.yaml b/cog.yaml index a02f5f1..d4b1520 100644 --- a/cog.yaml +++ b/cog.yaml @@ -3,7 +3,12 @@ build: gpu: true - python_version: "3.11" + python_version: "3.10" + system_packages: + - "ffmpeg" + - "libsm6" + - "libxext6" + - "libgl1" python_packages: - "torch==2.3.0" - "torchvision==0.18.0" From eec7aa3337f92096d7fac2f5f94ee0570741324f Mon Sep 17 00:00:00 2001 From: mbukeRepo Date: Sun, 7 Jul 2024 15:46:28 +0200 Subject: [PATCH 3/4] fix: clean up --- cog.yaml | 1 + predict.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cog.yaml b/cog.yaml index d4b1520..5f49853 100644 --- a/cog.yaml +++ b/cog.yaml @@ -29,4 +29,5 @@ build: - "matplotlib==3.9.0" - "imageio-ffmpeg==0.5.1" - "tyro==0.8.5" + - "gradio==3.48.0" predict: "predict.py:Predictor" diff --git a/predict.py b/predict.py index f0957b2..8aca41e 100644 --- a/predict.py +++ b/predict.py @@ -1,9 +1,10 @@ -from cog import BasePredictor, Input, Path +from cog import BasePredictor, Input, Path, File from src.config.argument_config import ArgumentConfig from src.config.inference_config import InferenceConfig from src.config.crop_config import CropConfig from src.live_portrait_pipeline import LivePortraitPipeline +import requests class Predictor(BasePredictor): @@ -16,14 +17,18 @@ class Predictor(BasePredictor): def predict( self, - image: Path = Input(description="Portrait image"), - driving_info: Path = Input( - description="driving video or template (.pkl format)" - ), + image: Path = Input(description="Portrait image") ) -> Path: """Run a single prediction on the model""" + video_path, _ = self.live_portrait_pipeline.execute( - ArgumentConfig(source_image=image, driving_info=driving_info, output_dir="/tmp/") + ArgumentConfig( + source_image=image, + driving_info="assets/examples/driving/d0.mp4", + output_dir="/tmp/", + flag_pasteback=False, + flag_do_crop=False, + ) ) return Path(video_path) From 8536882471b8ea6892d752bde6e75d2177e4eadf Mon Sep 17 00:00:00 2001 From: mbukeRepo Date: Mon, 8 Jul 2024 08:24:19 +0200 Subject: [PATCH 4/4] fix: clean up --- predict.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/predict.py b/predict.py index 8aca41e..b6cd637 100644 --- a/predict.py +++ b/predict.py @@ -6,7 +6,6 @@ from src.config.crop_config import CropConfig from src.live_portrait_pipeline import LivePortraitPipeline import requests - class Predictor(BasePredictor): def setup(self) -> None: """Load the model into memory to make running multiple predictions efficient""" @@ -17,18 +16,27 @@ class Predictor(BasePredictor): def predict( self, - image: Path = Input(description="Portrait image") + input_image_path: Path = Input(description="Portrait image"), + input_video_path: Path = Input(description="Driving video"), + flag_relative_input: bool = Input(description="relative motion", default=True), + flag_do_crop_input: bool = Input(description="We recommend checking the do crop option when facial areas occupy a relatively small portion of your image.", default=True), + flag_pasteback: bool = Input(description="paste-back", default=True), ) -> Path: """Run a single prediction on the model""" + user_args = ArgumentConfig( + flag_relative=flag_relative_input, + flag_do_crop=flag_do_crop_input, + flag_pasteback=flag_pasteback, + source_image=input_image_path, + driving_info=str(input_video_path), + output_dir="/tmp/" + ) + self.live_portrait_pipeline.cropper.update_config(user_args.__dict__) + self.live_portrait_pipeline.live_portrait_wrapper.update_config(user_args.__dict__) + video_path, _ = self.live_portrait_pipeline.execute( - ArgumentConfig( - source_image=image, - driving_info="assets/examples/driving/d0.mp4", - output_dir="/tmp/", - flag_pasteback=False, - flag_do_crop=False, - ) + user_args ) return Path(video_path)