forked from Rudrabha/Wav2Lip
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75de7f4
commit d175fa1
Showing
12 changed files
with
589 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
FROM nvidia/cuda:11.6.2-cudnn8-devel-ubuntu20.04 | ||
|
||
ARG DEBIAN_FRONTEND=noninteractive | ||
|
||
# install python via pyenv | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
make \ | ||
build-essential \ | ||
libssl-dev \ | ||
zlib1g-dev \ | ||
libbz2-dev \ | ||
libreadline-dev \ | ||
libsqlite3-dev \ | ||
wget \ | ||
curl \ | ||
llvm \ | ||
libncurses5-dev \ | ||
libncursesw5-dev \ | ||
xz-utils \ | ||
tk-dev \ | ||
libffi-dev \ | ||
liblzma-dev \ | ||
git \ | ||
ca-certificates \ | ||
libgl1 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
ENV PATH="/root/.pyenv/shims:/root/.pyenv/bin:$PATH" | ||
ARG PYTHON_VERSION=3.8 | ||
RUN curl -s -S -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash && \ | ||
pyenv install $PYTHON_VERSION && \ | ||
pyenv global $PYTHON_VERSION | ||
|
||
# install cog | ||
RUN pip install cog | ||
|
||
# install deps | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
ffmpeg libsndfile1 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# copy to /src | ||
ENV WORKDIR /src | ||
RUN mkdir -p $WORKDIR | ||
WORKDIR $WORKDIR | ||
|
||
# install requirements | ||
COPY requirements.txt . | ||
RUN pip install -r requirements.txt | ||
RUN pip install git+https://github.com/elliottzheng/batch-face.git@master | ||
|
||
# copy sources | ||
COPY . . | ||
|
||
ENV PYTHONUNBUFFERED=1 | ||
|
||
# run cog | ||
CMD python3 -m cog.server.http |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Configuration for Cog ⚙️ | ||
# Reference: https://github.com/replicate/cog/blob/main/docs/yaml.md | ||
|
||
image: r8.im/devxpy/cog-wav2lip | ||
|
||
build: | ||
# set to true if your model requires a GPU | ||
gpu: true | ||
cuda: "11.6.2" | ||
|
||
# a list of ubuntu apt packages to install | ||
system_packages: | ||
- ffmpeg | ||
- cmake | ||
|
||
# python version in the form '3.8' or '3.8.12' | ||
python_version: "3.8" | ||
|
||
# a list of packages in the format <package-name>==<version> | ||
python_packages: | ||
- numpy==1.23.4 | ||
- librosa==0.7.0 | ||
- opencv-python==4.6.0.66 | ||
- torch==1.12.1+cu116 --extra-index-url=https://download.pytorch.org/whl/cu116 | ||
- torchvision==0.13.1+cu116 --extra-index-url=https://download.pytorch.org/whl/cu116 | ||
- tqdm==4.45.0 | ||
- numba==0.48 | ||
- mediapipe==0.8.11 | ||
|
||
# commands run after the environment is setup | ||
run: | ||
- pip install git+https://github.com/elliottzheng/batch-face.git@master | ||
|
||
# predict.py defines how predictions are run on your model | ||
predict: "predict.py:Predictor" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import cv2 | ||
import mediapipe as mp | ||
|
||
mp_face_mesh = mp.solutions.face_mesh | ||
mp_drawing = mp.solutions.drawing_utils | ||
mp_drawing_styles = mp.solutions.drawing_styles | ||
mp_face_detection = mp.solutions.face_detection | ||
|
||
|
||
def face_rect(images): | ||
with mp_face_detection.FaceDetection( | ||
model_selection=1, min_detection_confidence=0.5 | ||
) as face_detection: | ||
for image_cv2 in images: | ||
# Convert the BGR image to RGB and process it with MediaPipe Face Detection. | ||
results = face_detection.process(cv2.cvtColor(image_cv2, cv2.COLOR_BGR2RGB)) | ||
|
||
# Draw face detections of each face. | ||
if not results.detections: | ||
yield None | ||
for detection in results.detections: | ||
yield _get_bounding_rect(image_cv2, detection) | ||
|
||
|
||
def _get_bounding_rect( | ||
image: mp_drawing.np.ndarray, | ||
detection: mp_drawing.detection_pb2.Detection, | ||
): | ||
""" | ||
Stolen from mediapipe.solutions.drawing_utils.draw_detection() | ||
""" | ||
if not detection.location_data: | ||
return | ||
if image.shape[2] != mp_drawing._BGR_CHANNELS: | ||
raise ValueError("Input image must contain three channel bgr data.") | ||
image_rows, image_cols, _ = image.shape | ||
|
||
location = detection.location_data | ||
|
||
# get bounding box if exists. | ||
if not location.HasField("relative_bounding_box"): | ||
return | ||
relative_bounding_box = location.relative_bounding_box | ||
rect_start_point = mp_drawing._normalized_to_pixel_coordinates( | ||
relative_bounding_box.xmin, relative_bounding_box.ymin, image_cols, image_rows | ||
) | ||
rect_end_point = mp_drawing._normalized_to_pixel_coordinates( | ||
relative_bounding_box.xmin + relative_bounding_box.width, | ||
relative_bounding_box.ymin + relative_bounding_box.height, | ||
image_cols, | ||
image_rows, | ||
) | ||
|
||
return *rect_start_point, *rect_end_point | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.