hacksider / Deep-Live-Cam

real time face swap and one-click video deepfake with only a single image
GNU Affero General Public License v3.0
35.17k stars 4.98k forks source link

Dockerize it #208

Open acebot712 opened 1 month ago

acebot712 commented 1 month ago

A lot of the dependencies are not working well out-of-the box. Please containainerize the applications and add instructions on README for the same.

sostenesapollo commented 1 month ago

Please add the python version and the requirements.txt updated

ngaer commented 1 month ago

Here's the docker config I use for running with cuda:

# Use NVIDIA CUDA base image
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1

# Install system dependencies
RUN apt-get update && apt-get install -y \
    python3.10-tk \
    python3-pip \
    git \
    ffmpeg \
    libsm6 \
    libxext6 \
    libgl1-mesa-glx \
    wget \
    && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Clone the repository
RUN git clone https://github.com/hacksider/Deep-Live-Cam.git .

# Install Python dependencies
RUN pip3 install --no-cache-dir -r requirements.txt

# Install ONNX Runtime GPU
RUN pip3 uninstall -y onnxruntime onnxruntime-gpu && \
    pip3 install --no-cache-dir onnxruntime-gpu==1.16.3

# Download required models
RUN mkdir -p models && \
    wget -O models/GFPGANv1.4.pth https://huggingface.co/hacksider/deep-live-cam/resolve/main/GFPGANv1.4.pth && \
    wget -O models/inswapper_128_fp16.onnx https://huggingface.co/hacksider/deep-live-cam/resolve/main/inswapper_128_fp16.onnx

# Set the entrypoint
ENTRYPOINT ["python3", "run.py", "--execution-provider", "cuda"]

# Default command (can be overridden)
CMD ["--help"]

And to run

# Build
docker build -t deep-live-cam .

# Run
docker run --gpus all \
      -v ./input:/app/input \
      -v ./output:/app/output \
      deep-live-cam \
      -s input/face.jpg \
      -t input/video.mp4\
      -o output
julienlau commented 1 month ago

Thanks for sharing.

Another version of your dockerfile a bit smaller

deep-live-cam                          latest    ee4a82ebe7dd   About an hour ago   22.2GB
pepitedata/deep-live-cam               latest    c4723be2b173   48 minutes ago      18.8GB
# Use NVIDIA CUDA base image
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1

# Install system dependencies
RUN apt-get update && apt-get install -y \
    python3.10-tk \
    python3-pip \
    git \
    ffmpeg \
    libsm6 \
    libxext6 \
    libgl1-mesa-glx \
    wget \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Clone the repository
RUN git clone https://github.com/hacksider/Deep-Live-Cam.git .

# Install Python dependencies
RUN pip3 install --no-cache-dir -r requirements.txt && \
    pip3 uninstall -y onnxruntime onnxruntime-gpu && \
    pip3 install --no-cache-dir onnxruntime-gpu==1.16.3 && \
    mkdir -p models && \
    wget -O models/GFPGANv1.4.pth https://huggingface.co/hacksider/deep-live-cam/resolve/main/GFPGANv1.4.pth && \
    wget -O models/inswapper_128_fp16.onnx https://huggingface.co/hacksider/deep-live-cam/resolve/main/inswapper_128_fp16.onnx && \
    pip3 cache purge && \
    rm -rf /var/lib/apt/lists/*

# Set the entrypoint
ENTRYPOINT ["python3", "run.py", "--execution-provider", "cuda"]

# Default command (can be overridden)
CMD ["--help"]

However, with both of them I got an error on ubuntu 24.04 nvidia-container-cli: initialization error: load library failed: libnvidia-ml.so.1: cannot open shared object file: no such file or directory: unknown.

reahari commented 3 weeks ago

Please add the python version and the requirements.txt updated

Which python version do you need/use? I'm using 3.12.3 and a lot of the dependencies can't be installed

julienlau commented 3 weeks ago

It is stated in the README : python 3.10

AVGRadmin commented 1 week ago

I've created a separate fork where i'm using docker containers (Linux tested only). I do have a image that uses Cuda 11.8 on the Hub, but i prefer 12.2 since i need it on my host computer for the majority of my other projects. The 11.8 image haven't been updated to work on the latest setup i have, so i would have to to some modifications in the Dockerfile for that to work. However, my fork is "plug&play" for me with Cuda 12.2. Face swapping and Enhancing works perfectly, but i haven't looked at the UI part or live webcam since i'm not really interested in that. If anyone is interested then it's just make to download all the models, and make run to start the app. I have a bash script that take care of arguments passed on to the application.

I'm just mentioning in case anyone is interested in trying it for themselves. But i have no plans to make a pull request to the original repo tho since this is just for my own usage that i made it.

Edit: My docker image is also public on the hub so you don't need to build it yourself if you don't want to ;)

julienlau commented 1 week ago

Thanks for sharing, I am surprised that you make it work with cuda 12. I tried it on my host (without using docker) and I had no success.

AVGRadmin commented 1 week ago

Yeah i had some issues there myself. One thing i had to do is to switch from inswapper_128_fp16.onnxto use inswapper_128.onnx instead. But i can't really say if this is the "fix" for getting it to work with Cuda 12 or not. I'm honestly just trying out stuff for fun here, and i've been going back and forth on the Docker image to get the final version xD

AVGRadmin commented 1 week ago

I've created a "Overhead" repo (Linux only) where you can choose to use different forks/repositories to run the application. It doesn't work out-of-the box with the original repo because of some errors i get when i use the default model there (inswapper_128_fp16). But it does work on that after changing a line as i mentioned in my previous comment. However, it does work out-of-the-box on my two computers with my fork and iRoopDeepFaceCam.