分享

DragGAN重磅开源,Windows安装指南

 一介书生五十后 2023-07-09 发布于浙江

昨天,期待已久的 DragGAN 终于开源啦,创新的通过拖拽方式进行P图,自动进行整个图片的调整,非常惊艳。

官方只说明了 Linux 下的安装方法,今天我们在Windows上安装使用,帮大家踩一些坑。

图片

环境准备

DragGAN的环境与 NVlabs/stylegan3 是相同的,作者将这个 environment.yml 也放到工程目录里了,先看一下

name: stylegan3
channels:
- pytorch
- nvidia
dependencies:
- python >= 3.8
- pip
- numpy>=1.20
- click>=8.0
- pillow=8.3.1
- scipy=1.7.1
- pytorch=1.9.1
- cudatoolkit=11.1
- requests=2.26.0
- tqdm=4.62.2
- ninja=1.10.2
- matplotlib=3.4.2
- imageio=2.9.0
- pip:
- imgui==1.3.0
- glfw==2.2.0
- pyopengl==3.1.5
- imageio-ffmpeg==0.4.3
- pyspng

直接这样安装比较慢,torch希望安装本地的CUDA对应的GPU版本。将 pytorch, pytorch=1.9.1 删掉,另外环境命名为 draggan,最终改为如下:

name: draggan
channels:
- nvidia
dependencies:
- python >= 3.8
- pip
- numpy>=1.20
- click>=8.0
- pillow=8.3.1
- scipy=1.7.1
- requests=2.26.0
- tqdm=4.62.2
- ninja=1.10.2
- matplotlib=3.4.2
- imageio=2.9.0
- pip:
- imgui==1.3.0
- glfw==2.2.0
- pyopengl==3.1.5
- imageio-ffmpeg==0.4.3
- pyspng

进入conda环境

conda env create -f environment_new.yml

查看python版本

activate draggan
python --version
Python 3.9.16

显示 python 3.9.16,安装 torch 选择cp39版本,手工安装:

pip install d:\pylib\torch-2.0.0+cu117-cp39-cp39-win_amd64.whl
pip install d:\pylib\torchvision-0.15.0+cu117-cp39-cp39-win_amd64.whl

安装项目

cd d:\aiWorkFlow
git clone https://github.com/XingangPan/DragGAN.git
cd DragGAN

下载模型

项目原来是执行 script/download_model.sh 下载模型,打开 .sh 看了一下。先是创建一个 checkpoints 目录,然后将模型文件下载到目录内,并有改名的动作。因为网络原因,wget下载容易中断,于是改成手动,用其他专业下载工具下载,例如: Free Donwload Manager

mkdir checkpoints
cd checkpoints

wget https://storage./self-distilled-stylegan/lions_512_pytorch.pkl
mv lions_512_pytorch.pkl stylegan2_lions_512_pytorch.pkl

wget https://storage./self-distilled-stylegan/dogs_1024_pytorch.pkl
mv dogs_1024_pytorch.pkl stylegan2_dogs_1024_pytorch.pkl

wget https://storage./self-distilled-stylegan/horses_256_pytorch.pkl
mv horses_256_pytorch.pkl stylegan2_horses_256_pytorch.pkl

wget https://storage./self-distilled-stylegan/elephants_512_pytorch.pkl
mv elephants_512_pytorch.pkl stylegan2_elephants_512_pytorch.pkl

wget https://api.ngc./v2/models/nvidia/research/stylegan2/versions/1/files/stylegan2-ffhq-512x512.pkl
wget https://api.ngc./v2/models/nvidia/research/stylegan2/versions/1/files/stylegan2-afhqcat-512x512.pkl
wget http://d36zk2xti64re0./stylegan2/networks/stylegan2-car-config-f.pkl
wget http://d36zk2xti64re0./stylegan2/networks/stylegan2-cat-config-f.pkl

以下两个真人模型可选下载,需要到 google driver,同样放到目录内:

https://drive.google.com/file/d/1dlFEHbu-WzQWJl7nBBZYcTyo000H9hVm/view?usp=sharing
https://drive.google.com/file/d/16twEf0T9QINAEoMsWefoWiyhcTd-aiWc/view?usp=sharing

最终文件如下:

图片

运行项目

python visualizer_drag.py checkpoints/stylegan2_lions_512_pytorch.pkl checkpoints/stylegan2-ffhq-512x512.pkl checkpoints/stylegan2-afhqcat-512x512.pkl checkpoints/stylegan2-car-config-f.pkl checkpoints/stylegan2_dogs_1024_pytorch.pkl checkpoints/stylegan2_horses_256_pytorch.pkl checkpoints/stylegan2-cat-config-f.pkl checkpoints/stylegan2_elephants_512_pytorch.pkl checkpoints/stylegan_human_v2_512.pkl checkpoints/stylegan2-lhq-256x256.pkl

这时应该能弹出窗口,看到左边的操作栏。

图片

如果主界面显示狮子,则一切正常。如果像上图一样提示找不到 MSVC 编译器,则需要安装MSVC编译器并正确设置路径。

图片

安装MSVC环境

打开以下 MS Visual Studio 下载页面:

visualstudio.microsoft.com/zh-hans/downloads/

下载社区版

图片

运行后,选择C++部分即可

图片

最后,指定下安装位置。

安装完毕后,找到安装目录下的路径,如我本机是

D:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64

打开 torch_utils\custom_ops.py,添加编译器路径

图片

再次运行项目

python visualizer_drag.py checkpoints/stylegan2_lions_512_pytorch.pkl checkpoints/stylegan2-ffhq-512x512.pkl checkpoints/stylegan2-afhqcat-512x512.pkl  checkpoints/stylegan2-car-config-f.pkl checkpoints/stylegan2_dogs_1024_pytorch.pkl checkpoints/stylegan2_horses_256_pytorch.pkl checkpoints/stylegan2-cat-config-f.pkl checkpoints/stylegan2_elephants_512_pytorch.pkl checkpoints/stylegan_human_v2_512.pkl checkpoints/stylegan2-lhq-256x256.pkl

这次应该能看到狮子了

图片

操作和效果

  • Recent:选择不同的模型对象, 就是刚才下载到 checkpoints 目录内的。也可以通过静态图像自己生成,这需要用到 PTI (https://github.com/danielroich/PTI)项目
  • Latent: 选择画面不同的姿态
  • Step: 每次动画的步度(快慢)
  • Reset: 图片回到初始状态
  • Add Point: 添加起点和终点
  • Reset Point: 清除选择点
  • Start/Stop: 变换开始/停止
  • Mask: 设置固定和可动区域

项目主页

github.com/XingangPan/DragGAN

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多