facechain_demo.ipynb 4.32 KB
Newer Older
chenzk's avatar
v1.0  
chenzk committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
{
 "nbformat": 4,
 "nbformat_minor": 0,
 "metadata": {
  "colab": {
   "private_outputs": true,
   "provenance": [],
   "machine_shape": "hm",
   "name": "facechain-demo.ipynb"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  }
 },
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "Requirements:\n",
    "- GPU Mem Usage: 19G\n",
    "- Disk Usage: About 50G"
   ],
   "metadata": {
    "id": "AzOycrSUkK-0"
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Get facechain source code from GitHub"
   ],
   "metadata": {
    "id": "8yQEWTkekIx9"
   }
  },
  {
   "cell_type": "code",
   "source": [
    "!GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/modelscope/facechain.git --depth 1"
   ],
   "metadata": {
    "id": "WK_uDw0NkHTP"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Installation requirements\n",
    "- Note that you can ignore warning on dependencies conflicts at the end\n",
    "- You may use conda virtual env to avoid warning info."
   ],
   "metadata": {
    "id": "jUWWSGDG1ZGK"
   }
  },
  {
   "cell_type": "code",
   "source": [
    "!pip3 install -r facechain/requirements.txt"
   ],
   "metadata": {
    "id": "QrwRDBipxKZw"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Check environment informaiton"
   ],
   "metadata": {
    "id": "0miaB1nC2VrA"
   }
  },
  {
   "cell_type": "code",
   "source": [
    "!nvidia-smi\n",
    "!pip3 show torch\n",
    "\n",
    "# Note that this setup is verified on (cuda 12.0, torch2.0.1+cu118, Nvidia-A100 40G)"
   ],
   "metadata": {
    "id": "uvNE0kRxyI4q"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "id": "klba298h2bbu"
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Installing mmcv-full\n",
    "- Several of the underlying models depend on mmcv-full, which could be tricky to install since it is environment-dependent, you may refer to [mmcv's official documentation](https://mmcv.readthedocs.io/zh_CN/latest/get_started/installation.html) for more details..\n",
    "- A prebuilt package is provided here for convenience, and was verified on (cuda 12.0, torch2.0.1+cu118, Nvidia-A100 40G)\n",
    "- If the prebuilt package does not work on your env setup, please use the alternative installation as suggested by [mmcv's official documentation](https://mmcv.readthedocs.io/zh_CN/latest/get_started/)"
   ],
   "metadata": {
    "id": "ciSxxSzI4l_u"
   }
  },
  {
   "cell_type": "code",
   "source": [
    "# use prebuilt mmcv-full package provided by ModelScope (verified on cuda 12.0, torch2.0.1+cu118, Nvidia-A100 40G)\n",
    "!pip3 install https://modelscope.oss-cn-beijing.aliyuncs.com/packages/mmcv/mmcv_full-1.7.0-cp310-cp310-linux_x86_64.whl\n",
    "\n",
    "# alternative manual installtation. note that it may take 30+ mins for building dependencies.\n",
    "# !pip3 install -U openmim\n",
    "# !mim install mmcv-full==1.7.0\n"
   ],
   "metadata": {
    "id": "t2lciBXyyuzA"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Pre-download models to mitigate connection timeout issue"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "import os\n",
    "os.chdir('/content/facechain') # Note: replace with your facechain root\n",
    "print(os.getcwd())\n",
    "\n",
    "# Not required\n",
    "from facechain.utils import pre_download_models\n",
    "pre_download_models()"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Start facechain WebUI service"
   ],
   "metadata": {
    "id": "OxDgRY8H4vta"
   }
  },
  {
   "cell_type": "code",
   "source": [
    "# Install service dependencies\n",
    "!pip3 install gradio==3.50.2\n",
    "!pip3 install controlnet_aux==0.0.6\n",
    "!pip3 install python-slugify\n",
    "!pip3 install onnxruntime==1.15.1\n",
    "!pip3 install edge-tts\n",
    "\n",
    "# Click on the gradio URL to start building your FaceChain digital-twin!\n",
    "!python3 app.py"
   ],
   "metadata": {
    "id": "NW5o0iiezTCg"
   },
   "execution_count": null,
   "outputs": []
  }
 ]
}