Skip to content

Commit 5638984

Browse files
mikaelhgmonsterusermintmaker
authored
Dockerize the "Remote GPU" service (#224)
* Dockerfile * add docker support in run.sh and readme * Update README * Update TOC * Update TOC * Fix headless error * use GPU as default * Update README.md * Create install_docker.sh * update install for v4l2loopback Co-authored-by: monsteruser <[email protected]> Co-authored-by: mintmaker <[email protected]>
1 parent 56e8f6d commit 5638984

File tree

4 files changed

+162
-20
lines changed

4 files changed

+162
-20
lines changed

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM nvcr.io/nvidia/cuda:10.0-cudnn7-runtime-ubuntu18.04
2+
3+
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq update \
4+
&& DEBIAN_FRONTEND=noninteractive apt-get -qqy install curl python3-pip python3-tk ffmpeg git less nano libsm6 libxext6 libxrender-dev \
5+
&& rm -rf /var/lib/apt/lists/*
6+
7+
ARG PYTORCH_WHEEL="https://download.pytorch.org/whl/cu100/torch-1.0.0-cp36-cp36m-linux_x86_64.whl"
8+
ARG FACE_ALIGNMENT_GIT="git+https://github.com/1adrianb/face-alignment"
9+
ARG AVATARIFY_COMMIT="01db88c8580b982278ae944b89b3bfab5d98c1dd"
10+
ARG FOMM_COMMIT="efbe0a6f17b38360ff9a446fddfbb3ce5493534c"
11+
12+
RUN git clone https://github.com/alievk/avatarify.git /app/avatarify && cd /app/avatarify && git checkout ${AVATARIFY_COMMIT} \
13+
&& git clone https://github.com/alievk/first-order-model.git /app/avatarify/fomm && cd /app/avatarify/fomm && git checkout ${FOMM_COMMIT}
14+
15+
WORKDIR /app/avatarify
16+
17+
RUN bash scripts/download_data.sh
18+
19+
RUN pip3 install ${PYTORCH_WHEEL} ${FACE_ALIGNMENT_GIT} -r requirements.txt \
20+
&& pip3 install ${PYTORCH_WHEEL} ${FACE_ALIGNMENT_GIT} -r fomm/requirements.txt \
21+
&& rm -rf /root/.cache/pip
22+
23+
ENV PYTHONPATH="/app/avatarify:/app/avatarify/fomm"
24+
25+
EXPOSE 5557
26+
EXPOSE 5558
27+
28+
CMD ["python3", "afy/cam_fomm.py", "--config", "fomm/config/vox-adv-256.yaml", "--checkpoint", "vox-adv-cpk.pth.tar", "--virt-cam", "9", "--relative", "--adapt_scale", "--is-worker"]

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Created by: GitHub community.
3232
- [Mac](#mac)
3333
- [Windows](#windows)
3434
- [Remote GPU](#remote-gpu)
35+
- [Docker](#docker)
3536
- [Setup avatars](#setup-avatars)
3637
- [Run](#run)
3738
- [Linux](#linux-1)
@@ -87,6 +88,7 @@ bash scripts/install.sh
8788
```
8889
3. [Download network weights](#download-network-weights) and place `vox-adv-cpk.pth.tar` file in the `avatarify` directory (don't unpack it).
8990

91+
9092
#### Mac
9193
*(!) Note*: we found out that in versions after [v4.6.8 (March 23, 2020)](https://zoom.us/client/4.6.19178.0323/ZoomInstaller.pkg) Zoom disabled support for virtual cameras on Mac. To use Avatarify in Zoom you can choose from 2 options:
9294
- Install [Zoom v4.6.8](https://zoom.us/client/4.6.19178.0323/ZoomInstaller.pkg) which is the last version that supports virtual cameras
@@ -137,8 +139,23 @@ The steps 10-11 are required only once during setup.
137139

138140
#### Remote GPU
139141

140-
You can offload the heavy work to [Google Colab](https://colab.research.google.com/github/alievk/avatarify/blob/master/avatarify.ipynb) or a [server with a GPU](https://github.com/alievk/avatarify/wiki/Remote-GPU) and use your laptop just to communicate the video stream.
142+
You can offload the heavy work to [Google Colab](https://colab.research.google.com/github/alievk/avatarify/blob/master/avatarify.ipynb) or a [server with a GPU](https://github.com/alievk/avatarify/wiki/Remote-GPU) and use your laptop just to communicate the video stream. The server and client software are native and dockerized available.
143+
144+
### Docker
145+
Docker images are only availabe on Linux.
141146

147+
1. Install Docker following the [Documentation](https://docs.docker.com/engine/install/). Then run this [step](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user) to make docker available for your user.
148+
2. For using the gpu (hardly recommended): Install nvidia drivers and [nvidia docker](https://github.com/NVIDIA/nvidia-docker#quickstart).
149+
3. Clone `avatarify` and install its dependencies (v4l2loopback kernel module):
150+
```bash
151+
git clone https://github.com/alievk/avatarify.git
152+
cd avatarify
153+
bash scripts/install_docker.sh
154+
```
155+
4. Build the Dockerfile:
156+
```bash
157+
docker build -t avatarify
158+
```
142159
## Setup avatars
143160
Avatarify comes with a standard set of avatars of famous people, but you can extend this set simply copying your avatars into `avatars` folder.
144161

@@ -162,6 +179,7 @@ Run:
162179
```bash
163180
bash run.sh
164181
```
182+
If you haven't installed a GPU add the `--no-gpus` flag. In order to use Docker add the `--docker` flag.
165183

166184
`cam` and `avatarify` windows will pop-up. The `cam` window is for controlling your face position and `avatarify` is for the avatar animation preview. Please follow these [recommendations](#driving-your-avatar) to drive your avatars.
167185

run.sh

Lines changed: 106 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
ENABLE_CONDA=1
66
ENABLE_VCAM=1
77
KILL_PS=1
8+
USE_DOCKER=0
9+
IS_WORKER=0
10+
IS_CLIENT=0
11+
DOCKER_IS_LOCAL_CLIENT=0
12+
DOCKER_NO_GPU=0
813

914
FOMM_CONFIG=fomm/config/vox-adv-256.yaml
1015
FOMM_CKPT=vox-adv-cpk.pth.tar
1116

1217
ARGS=""
18+
DOCKER_ARGS=""
1319

1420
while (( "$#" )); do
1521
case "$1" in
@@ -26,6 +32,31 @@ while (( "$#" )); do
2632
KILL_PS=0
2733
shift
2834
;;
35+
--docker)
36+
USE_DOCKER=1
37+
shift
38+
;;
39+
--no-gpus)
40+
DOCKER_NO_GPU=1
41+
shift
42+
;;
43+
--is-worker)
44+
IS_WORKER=1
45+
ARGS="$ARGS $1"
46+
DOCKER_ARGS="$DOCKER_ARGS -p 5557:5557 -p 5558:5558"
47+
shift
48+
;;
49+
--is-client)
50+
IS_CLIENT=1
51+
ARGS="$ARGS $1"
52+
shift
53+
;;
54+
--is-local-client)
55+
IS_CLIENT=1
56+
DOCKER_IS_LOCAL_CLIENT=1
57+
ARGS="$ARGS --is-client"
58+
shift
59+
;;
2960
*|-*|--*)
3061
ARGS="$ARGS $1"
3162
shift
@@ -35,28 +66,84 @@ done
3566

3667
eval set -- "$ARGS"
3768

38-
if [[ $KILL_PS == 1 ]]; then
39-
kill -9 $(ps aux | grep 'afy/cam_fomm.py' | awk '{print $2}') 2> /dev/null
40-
fi
4169

42-
source scripts/settings.sh
4370

44-
if [[ $ENABLE_VCAM == 1 ]]; then
45-
bash scripts/create_virtual_camera.sh
46-
fi
71+
if [[ $USE_DOCKER == 0 ]]; then
72+
73+
if [[ $KILL_PS == 1 ]]; then
74+
kill -9 $(ps aux | grep 'afy/cam_fomm.py' | awk '{print $2}') 2> /dev/null
75+
fi
76+
77+
source scripts/settings.sh
78+
79+
if [[ $ENABLE_VCAM == 1 ]]; then
80+
bash scripts/create_virtual_camera.sh
81+
fi
82+
83+
if [[ $ENABLE_CONDA == 1 ]]; then
84+
source $(conda info --base)/etc/profile.d/conda.sh
85+
conda activate $CONDA_ENV_NAME
86+
fi
87+
88+
export PYTHONPATH=$PYTHONPATH:$(pwd):$(pwd)/fomm
89+
90+
python afy/cam_fomm.py \
91+
--config $FOMM_CONFIG \
92+
--checkpoint $FOMM_CKPT \
93+
--virt-cam $CAMID_VIRT \
94+
--relative \
95+
--adapt_scale \
96+
$@
97+
else
4798

48-
if [[ $ENABLE_CONDA == 1 ]]; then
49-
source $(conda info --base)/etc/profile.d/conda.sh
50-
conda activate $CONDA_ENV_NAME
51-
fi
99+
source scripts/settings.sh
100+
101+
if [[ $ENABLE_VCAM == 1 ]]; then
102+
bash scripts/create_virtual_camera.sh
103+
fi
104+
105+
if [[ $DOCKER_NO_GPU == 0 ]]; then
106+
DOCKER_ARGS="$DOCKER_ARGS --gpus all"
107+
fi
108+
109+
if [[ $DOCKER_IS_LOCAL_CLIENT == 1 ]]; then
110+
DOCKER_ARGS="$DOCKER_ARGS --network=host"
111+
elif [[ $IS_CLIENT == 1 ]]; then
112+
DOCKER_ARGS="$DOCKER_ARGS -p 5557:5554 -p 5557:5558"
113+
fi
52114

53-
export PYTHONPATH=$PYTHONPATH:$(pwd):$(pwd)/fomm
115+
54116

55-
python afy/cam_fomm.py \
56-
--config $FOMM_CONFIG \
57-
--checkpoint $FOMM_CKPT \
58-
--virt-cam $CAMID_VIRT \
59-
--relative \
60-
--adapt_scale \
61-
$@
117+
118+
if [[ $IS_WORKER == 0 ]]; then
119+
xhost +local:root
120+
docker run $DOCKER_ARGS -it --rm --privileged \
121+
-v $PWD:/root/.torch/models \
122+
-v $PWD/avatars:/app/avatarify/avatars \
123+
--env="DISPLAY" \
124+
--env="QT_X11_NO_MITSHM=1" \
125+
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
126+
avatarify python3 afy/cam_fomm.py \
127+
--config $FOMM_CONFIG \
128+
--checkpoint $FOMM_CKPT \
129+
--virt-cam $CAMID_VIRT \
130+
--relative \
131+
--adapt_scale \
132+
$@
133+
xhost -local:root
62134

135+
else
136+
docker run $DOCKER_ARGS -it --rm --privileged \
137+
-v $PWD:/root/.torch/models \
138+
-v $PWD/avatars:/app/avatarify/avatars \
139+
avatarify python3 afy/cam_fomm.py \
140+
--config $FOMM_CONFIG \
141+
--checkpoint $FOMM_CKPT \
142+
--virt-cam $CAMID_VIRT \
143+
--relative \
144+
--adapt_scale \
145+
$@
146+
fi
147+
148+
149+
fi

scripts/install_docker.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if [[ ! $@ =~ "no-vcam" ]]; then
2+
rm -rf v4l2loopback 2> /dev/null
3+
git clone https://github.com/umlaeute/v4l2loopback
4+
echo "--- Installing v4l2loopback (sudo privelege required)"
5+
cd v4l2loopback
6+
make && sudo make install
7+
sudo depmod -a
8+
cd ..
9+
fi

0 commit comments

Comments
 (0)