0. 引言
编程环境配置:客户端(Window 11、PyCharm 2022.1.3),服务器端为Ubuntu,其中PyCharm使用SSH技术连接Ubuntu终端进行开发
1. Python环境配置
RTX 3090芯片(CUDA版本需要11.1及以上,否则会因为算力太高无法运行程序)
CUDA 11.1
Python 3
PyTorch ==1.9.0
MMCV-Full >= 1.4.2 <= 1.9.0
MMGeneration >= 0.3.0
2. 安装步骤
2.1 创建虚拟环境
我们首先创建conda虚拟环境并对它进行激活
conda create -n facestylor python=3.7 -y
conda activate facestylor
假设您已经安装了CUDA 11.1,您需要使用CUDA 11.1安装预构建的PyTorch。
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
2.2 安装MMCV和MMGEN
我们可以通过运行以下命令来安装MMCV
pip install mmcv-full==1.4.2 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html
当然我们还可以通过MMCV文档进行安装(命令行安装或者源码编译)
然后,我们应该安装包含将在本项目中使用的基本生成模型的MMGEN。
# Clone the MMGeneration repository.
git clone https://github.com/open-mmlab/mmgeneration.git
cd mmgeneration
# Install build requirements and then install MMGeneration.
pip install -r requirements.txt
pip install -v -e . # or "python setup.py develop"
cd ..
-v : verbose,or more output.(输出更详细的信息)
-e : installing a project in editable mode.(以可编辑的模式安装项目)
. : 一个点,代表相对路径,也就是当前路径(代表路径)
2.3 克隆存储库并准备数据和权重
现在,我们需要克隆这个存储库并安装依赖。
git clone https://github.com/open-mmlab/MMGEN-FaceStylor.git
cd MMGEN-FaceStylor
pip install -r requirements.txt
为了方便起见,我们在MMGEN-FaceStylor中创建以下的文件夹。
mkdir data
mkdir work_dirs
mkdir work_dirs/experiments
mkdir work_dirs/pre-trained
对于test和train,您需要下载AgileGAN提供的一些必要数据并将它们放在数据文件夹下。或者只是运行以下命令:
wget的使用方法详解
wget --no-check-certificate 'https://docs.google.com/uc?export=download&id=1AavRxpZJYeCrAOghgtthYqVB06y9QJd3' -O data/shape_predictor_68_face_landmarks.dat
然后,您可以在data文件夹下放置或创建数据的软连接,并将您的实验结果放在work_dirs/experiments。
或者:
wget --no-check-certificate https://github.com/JeffTrain/selfie/raw/master/shape_predictor_68_face_landmarks.dat -O data/shape_predictor_68_face_landmarks.dat
我们也可以提供一些预训练好的权重。
3. Play with MMGEN-FaceStylor
3.1 Quick Try
我们可以运行以下指令来快速尝试项目
python demo/quick_try.py demo/src.png --style toonify
然后你就可以在work_dirs/demos/agile_result.png中查看结果。
可以使用的style类型有:toonify,oil,sketch,bitmoji,cartoon和comic。
如果运行上述命令出现问题,很可能是以下问题,写者这些盘点几个自己运行这段命令遇到的错误
1、CUDA11.1版本的安装与运行
2、conda使用不同版本的cuda