WIN10+CUDA10 +CUDNN7.5+ TENSORFLOW-GPU1.13.1 + python3.7 运行NVIDIA STYLEGAN 的安装过程和踩坑实录


最近在研究如何使用nvidia StyleGAN以及StyleGAN的运行方法,但是摸不着头绪,很幸运遇到群里的大神手把手指导,终于得以成功运行stylegan的pretrained_example.py官方实例……中间踩坑无数,在这里给大家讲讲避免踩坑的方法……
在此特别鸣谢星轨大佬,然后还有CSDN里面数不清的文章,遇到了许许多多的问题,看了几十篇文章,在此不再一一叙述,总之表示十分感谢。

有同学反应看不懂,我先把整个流程放上来:(WINDOWS平台)(20201130更新)

 

1.检查自己的硬件设备是否符合运行条件。

2.将自己的显卡驱动更新至符合要求的较高版本。

3.安装tensorflow-gpu运行需要的CUDA和配套的CUDNN库,并配置相关环境变量。

4.安装anaconda软件,并创建一个tensorflow-GPU的运行环境,在此环境内下载并部署tensorflow-gpu。

5.下载stylegan源码并尝试运行,如报错根据提示补充所缺的相关模块。

6.完美运行

 

以下开始正文部分:

 

首先先说一下我自己电脑运行环境:

系统:WIN10 64bit
显卡:GTX1070
CPU:AMD1800X
其他……16G内存等,个人建议固态硬盘,毕竟读取速度要快很多

 

对于计算机硬件来说,其实除了GPU要求高一些,其他问题都不大,可以对照英伟达的一个算力表来看自己的显卡适不适合CUDA加速。

在软件环境方面,个人推荐CUDA10.0+CUDNN7.5+tensorflow-gpu1.13.1+python3.7 这个版本搭配,因为自己跑通了,不同的CUDA,不同的tensorflow可能会有奇奇怪怪的问题。

网上说tensorflow-gpu1.13.1不支持CUDA10.1,我好像也确实遇到了这个问题,不建议安装。

20190326补充:朋友的CUDA9.0环境下也运行成功了,所以问题不大

官方给出的系统要求:

  • Linux和Windows都受支持,但出于性能和兼容性的原因,我们强烈建议使用Linux。
  • 64位Python 3.6安装。我们推荐使用numpy 1.14.3或更新的Anaconda3。
  • TensorFlow 1.10.0或更高版本,支持GPU。
  • 一个或多个具有至少11GB DRAM的高端NVIDIA GPU。我们推荐配备8个Tesla V100 GPU的NVIDIA DGX-1。(注:只是使用预训练的集生成图片不需要这么强大的显卡,训练自己的训练集就需要了)
  • NVIDIA驱动程序391.35或更高版本,CUDA工具包9.0或更高版本,cuDNN 7.3.1或更高版本。

 

首先是准备阶段:

1.你要知道一些linux基本命令,比如cd c:\xxxx(文件路径)是打开项目的文件夹、python xxxx.py是使用python运行这个py文件、pip install xxxxxx  我理解为是联网自动打包安装某个程序

2.你要拥有一块较高算力的NVIDIA显卡,可以从这个网站来获取CUDA的算力信息https://developer.nvidia.com/cuda-gpus
PS:前两天看到一篇文章,说GT1030算力居然有6.1(compute capability: 6.1),虽然不在老黄的名单中,但是这算力价格比可以说是性价比最高的CUDA加速卡了吧,和以下主流卡在同一个水平上…… 详见下图

compute capability

NVIDIA TITAN RTX7.5
Geforce RTX 2080 Ti7.5
Geforce RTX 20807.5
Geforce RTX 20707.5
Geforce RTX 20607.5
NVIDIA TITAN V7.0
NVIDIA TITAN X6.1
GeForce GTX 1080 Ti6.1
GeForce GTX 10806.1
GeForce GTX 10706.1
GeForce GTX 10606.1
GeForce GTX 10506.1

3.坚忍不拔的耐心……2333(我装好tensorflow环境至少花了10小时以上的时间,走了无数的弯路,如果按照正确的方法,其实应该很快就搞定的。)

4.更新显卡驱动版本更新为最新,或者在安装CUDA的时候卸载掉之前有的nvidia GeForce Experience,然后使用CUDA的安装包重新装一次。有时候因为
CUDA的安装包里面含有显卡驱动程序。我个人是删掉所有显卡驱动之后重装的,如果你之前安装了CUDA发现提示说
status: CUDA DRIVER VERSION is insufficient for cuda runtime version 的报错,其原因是因为显卡驱动的版本过低,在此附上英伟达CUDA最低支持的显卡驱动版本对应表

Table 1. CUDA Toolkit and Compatible Driver Versions
CUDA ToolkitLinux x86_64 Driver VersionWindows x86_64 Driver Version
CUDA 10.1.105>= 418.39>= 418.96
CUDA 10.0.130>= 410.48>= 411.31
CUDA 9.2 (9.2.148 Update 1)>= 396.37>= 398.26
CUDA 9.2 (9.2.88)>= 396.26>= 397.44
CUDA 9.1 (9.1.85)>= 390.46>= 391.29
CUDA 9.0 (9.0.76)>= 384.81>= 385.54
CUDA 8.0 (8.0.61 GA2)>= 375.26>= 376.51
CUDA 8.0 (8.0.44)>= 367.48>= 369.30
CUDA 7.5 (7.5.16)>= 352.31>= 353.66
CUDA 7.0 (7.0.28)>= 346.46>= 347.62

有两种办法查看当前电脑的显卡驱动版本:

https://blog.csdn.net/li57681522/article/details/82491617

右键打开我的电脑,在左侧边栏有个高级系统设置,右下角有个环境变量,上方方框里面有个ADMINISTRATOR(你电脑用户名)的用户变量,里面有个path值,双击打开,点击右侧新建,加入:C:\Program Files\NVIDIA Corporation\NVSMI

使用【win+R 输入cmd 】——回车执行,或者【开始菜单——运行——cmd】—— 回车执行
在DOS界面下输入
nvidia-smi

就可以看到当前显卡的驱动版本啦

或者你直接打开GeForce Experience 看当前驱动版本就行……不过这东西要登陆的,而且还有时候被墙,就很尴尬

 

确定硬件设备OK,驱动OK,之后可以开始安装工作了:

1.安装CUDA(建议使用CUDA10)

地址:https://developer.nvidia.com/cuda-10.0-download-archive?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal
这里是win10 32/64bit系统下载链接
如果你是MAC或者LINUX用户,以及其他版本比如win7用户,需要改成自己的系统(Version)要求下载
下载安装cuda10完成之后,必须下载对应版本的cudnn,其中cuda10对应的cudnn版本为cudnn-10.0-windows10-x64-v7.5.0.56或更高

cudnn下载地址和安装办法:
https://developer.nvidia.com/cudnn

这里需要注册填写一个调查问卷,然后下载cudnn对应cuda10.0版本的,注意别下成了10.1的,必须对应版本!

为了方便大家,我再放个网盘链接吧……

cudnn-10.0-windows10-x64-v7.6.4.38.zip

链接: https://pan.baidu.com/s/1qqUN5ZYBchYdrz0MPrf3yg&shfl=shareset

提取码: ghst

cudnn文件的放置方法和环境变量设置:

https://www.tensorflow.org/install/gpu#windows_setup
也就是说在C盘下新建一个tools的文件夹,把cudnn解压进去,然后再添加三个path的环境变量(如上面图倒数2-4个变量):

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\extras\CUPTI\libx64
C:\tools\cuda\bin
把下载的cudnn文件分别按照文件夹放到下面的目录:

cudnn\bin\cudnn64_5.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin\
cudnn\include\cudnn.h to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include\
cudnn\lib\x64\cudnn.lib to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64\

2.安装adaconda python3.7版本(stylegan需要python3.7的)

https://www.anaconda.com/distribution/

选择python3.7版本adaconda

以及下方的图形化界面安装版本:64-Bit Graphical Installer (652.7 MB)
在安装中,记得勾选
【√】JUST ME
然后选择完安装路径之后
勾选【√】:Add Anaconda to my PATH environment variable
个人觉得这样子好像有利于执行相关程序……

安装完成之后,开始菜单中  adaconda3文件夹下会出现Anaconda Prompt 这个应用程序,这个个人理解为一个虚拟机……类似linux,我们直接在这里执行安装代码,当然也可以用adaconda的图形化界面,但是觉得比较麻烦……

 

3.创建tensorflow-gpu需要的虚拟环境:

打开开始菜单中 adaconda3文件夹下Anaconda Prompt 程序
应该会显示  (base) C:\Users\Administrator> 
在这行文字之后输入:

conda create -n tensorflow-gpu python=3.7


这步就是在adaconda中创建一个名字叫做tensorflow-gpu的环境,其python版本为3.7
之后adaconda会自动创建,并且列出各种库的名字:
然后会问你yes or no
输入 y 按回车


就会自动创建环境了,当环境创建完成,会重新显示

(base) C:\Users\Administrator(这里的名字是你电脑的用户名)>

此时在后面输入


conda activate tensorflow-gpu


会发现这行文字显示为:


(tensorflow-gpu) C:\Users\Administrator>


代表环境创建完成并且已经通过上述命令激活进入了这个环境!

 

4.安装tensorflow1.13.1

打开开始菜单中 adaconda3文件夹下Anaconda Prompt 程序(刚才应该已经打开了),输入conda activate tensorflow-gpu进入tensorflow-gpu环境(如果上一 步走下来应该是已经进入了这个环境了)

此时应该显示的是:

(tensorflow-gpu) C:\Users\Administrator>

在这行文字之后输入:

pip install tensorflow-gpu    #(意思是直接打包安装tensorflow-gpu)#

或者:pip install –upgrade tensorflow-gpu
再或者保守的说(
2020年3月8日更新:大家看到文章的时候有tensorflow-gpu更新版本的了,,因为目前输入这段会被安装TS2.0+,这里高版本的tesorflow可能和stylegan不兼容),也可以选择输入:

pip install tensorflow-gpu==1.13.1

也就是安装指定版本的python

鉴于国内链接有时候不通畅,强烈推荐使用清华大学源安装tensorflow-gpu:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu==1.13.1

ps:如果这时候电脑报错说:

Youare using pip version 9.0.1, however version 1x.x.x is available.

Youshould consider upgrading via the ‘python -m pip install –upgrade pip’command.

那就先执行python -m pip install –upgrade pip 说明pip版本太老了,需要先更新pip版本再安装tensorflow-gpu

此时需要挂梯子或者代理!否则有可能没有速度,有时候安装会中断,所以可以多试几次
实在不行可以找找国内的缓存或者github的源

如果最后退回到(tensorflow-gpu) C:\Users\Administrator> 就说明安装完成,正常上面应该有显示successful

 

装完tensorflow-gpu之后应该会显示:

Installing collected packages: termcolor, gast, numpy, six, h5py, keras-applications, astor, grpcio, mock, absl-py, tensorflow-estimator, markdown, protobuf, werkzeug, tensorboard, keras-preprocessing, tensorflow-gpu
Successfully installed absl-py-0.7.1 astor-0.7.1 gast-0.2.2 grpcio-1.20.1 h5py-2.9.0 keras-applications-1.0.7 keras-preprocessing-1.0.9 markdown-3.1 mock-3.0.5 numpy-1.16.3 protobuf-3.7.1 six-1.12.0 tensorboard-1.13.1 tensorflow-estimator-1.13.0 tensorflow-gpu-1.13.1 termcolor-1.1.0 werkzeug-0.15.2

告诉你装成功了那些数学库什么的,版本是啥,这些不一定会全用到,但是如果你做其他机器学习的计算还是很需要的!

5.去github下载stylegan的源码

网址:https://github.com/NVlabs/stylegan
点击右边的clon or download按钮,然后点击download zip 就可以把程序打包下载到本机了!
下载完成之后,建议解压移动到C:\Users\Administrator文件夹下,因为这是adaconda默认的文件目录,比较好修改,也好连接
接下来,打开开始菜单中 adaconda3文件夹下Anaconda Prompt 程序

输入:activate tensorflow-gpu
再输入:cd C:\Users\Administrator\stylegan-master

此时应该显示

(tensorflow-gpu) C:\Users\Administrator\stylegan-master>

输入:python pretrained_example.py
如果报错:NO MODLE NAME “PIL”
说明缺少pillow库,运行:pip install pillow

再运行python pretrained_example.py,如果还报错:no modle named “requests”
运行:pip install requests

 

如果显示:download from :xxxxx 什么googlexxx什么的,代表正在下载参考数据集,大约300m左右,下载完成之后会运行下面程序:(大约只需要10秒钟左右就能生成一张照片:)

注意:此时必须挂梯子或者代理!否则有可能没有速度

(执行的参考结果如下:)

(tensorflow-gpu) C:\Users\Administrator\stylegan-master>python pretrained_example.pyWARNING:tensorflow:From C:\ProgramData\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.

(意思是有些乱七八糟的东西将在将来的版本中被移除,问题不大)

Gs Params OutputShape WeightShape
— — — —
latents_in – (?, 512) –
labels_in – (?, 0) –
lod – () –
dlatent_avg – (512,) –
G_mapping/latents_in – (?, 512) –
G_mapping/labels_in – (?, 0) –
G_mapping/PixelNorm – (?, 512) –
G_mapping/Dense0 262656 (?, 512) (512, 512)
G_mapping/Dense1 262656 (?, 512) (512, 512)
G_mapping/Dense2 262656 (?, 512) (512, 512)
G_mapping/Dense3 262656 (?, 512) (512, 512)
G_mapping/Dense4 262656 (?, 512) (512, 512)
G_mapping/Dense5 262656 (?, 512) (512, 512)
G_mapping/Dense6 262656 (?, 512) (512, 512)
G_mapping/Dense7 262656 (?, 512) (512, 512)
G_mapping/Broadcast – (?, 18, 512) –
G_mapping/dlatents_out – (?, 18, 512) –
Truncation – (?, 18, 512) –
G_synthesis/dlatents_in – (?, 18, 512) –
G_synthesis/4×4/Const 534528 (?, 512, 4, 4) (512,)
G_synthesis/4×4/Conv 2885632 (?, 512, 4, 4) (3, 3, 512, 512)
G_synthesis/ToRGB_lod8 1539 (?, 3, 4, 4) (1, 1, 512, 3)
G_synthesis/8×8/Conv0_up 2885632 (?, 512, 8, 8) (3, 3, 512, 512)
G_synthesis/8×8/Conv1 2885632 (?, 512, 8, 8) (3, 3, 512, 512)
G_synthesis/ToRGB_lod7 1539 (?, 3, 8, 8) (1, 1, 512, 3)
G_synthesis/Upscale2D – (?, 3, 8, 8) –
G_synthesis/Grow_lod7 – (?, 3, 8, 8) –
G_synthesis/16×16/Conv0_up 2885632 (?, 512, 16, 16) (3, 3, 512, 512)
G_synthesis/16×16/Conv1 2885632 (?, 512, 16, 16) (3, 3, 512, 512)
G_synthesis/ToRGB_lod6 1539 (?, 3, 16, 16) (1, 1, 512, 3)
G_synthesis/Upscale2D_1 – (?, 3, 16, 16) –
G_synthesis/Grow_lod6 – (?, 3, 16, 16) –
G_synthesis/32×32/Conv0_up 2885632 (?, 512, 32, 32) (3, 3, 512, 512)
G_synthesis/32×32/Conv1 2885632 (?, 512, 32, 32) (3, 3, 512, 512)
G_synthesis/ToRGB_lod5 1539 (?, 3, 32, 32) (1, 1, 512, 3)
G_synthesis/Upscale2D_2 – (?, 3, 32, 32) –
G_synthesis/Grow_lod5 – (?, 3, 32, 32) –
G_synthesis/64×64/Conv0_up 1442816 (?, 256, 64, 64) (3, 3, 512, 256)
G_synthesis/64×64/Conv1 852992 (?, 256, 64, 64) (3, 3, 256, 256)
G_synthesis/ToRGB_lod4 771 (?, 3, 64, 64) (1, 1, 256, 3)
G_synthesis/Upscale2D_3 – (?, 3, 64, 64) –
G_synthesis/Grow_lod4 – (?, 3, 64, 64) –
G_synthesis/128×128/Conv0_up 426496 (?, 128, 128, 128) (3, 3, 256, 128)
G_synthesis/128×128/Conv1 279040 (?, 128, 128, 128) (3, 3, 128, 128)
G_synthesis/ToRGB_lod3 387 (?, 3, 128, 128) (1, 1, 128, 3)
G_synthesis/Upscale2D_4 – (?, 3, 128, 128) –
G_synthesis/Grow_lod3 – (?, 3, 128, 128) –
G_synthesis/256×256/Conv0_up 139520 (?, 64, 256, 256) (3, 3, 128, 64)
G_synthesis/256×256/Conv1 102656 (?, 64, 256, 256) (3, 3, 64, 64)
G_synthesis/ToRGB_lod2 195 (?, 3, 256, 256) (1, 1, 64, 3)
G_synthesis/Upscale2D_5 – (?, 3, 256, 256) –
G_synthesis/Grow_lod2 – (?, 3, 256, 256) –
G_synthesis/512×512/Conv0_up 51328 (?, 32, 512, 512) (3, 3, 64, 32)
G_synthesis/512×512/Conv1 42112 (?, 32, 512, 512) (3, 3, 32, 32)
G_synthesis/ToRGB_lod1 99 (?, 3, 512, 512) (1, 1, 32, 3)
G_synthesis/Upscale2D_6 – (?, 3, 512, 512) –
G_synthesis/Grow_lod1 – (?, 3, 512, 512) –
G_synthesis/1024×1024/Conv0_up 21056 (?, 16, 1024, 1024) (3, 3, 32, 16)
G_synthesis/1024×1024/Conv1 18752 (?, 16, 1024, 1024) (3, 3, 16, 16)
G_synthesis/ToRGB_lod0 51 (?, 3, 1024, 1024) (1, 1, 16, 3)
G_synthesis/Upscale2D_7 – (?, 3, 1024, 1024) –
G_synthesis/Grow_lod0 – (?, 3, 1024, 1024) –
G_synthesis/images_out – (?, 3, 1024, 1024) –
G_synthesis/lod – () –
G_synthesis/noise0 – (1, 1, 4, 4) –
G_synthesis/noise1 – (1, 1, 4, 4) –
G_synthesis/noise2 – (1, 1, 8, 8) –
G_synthesis/noise3 – (1, 1, 8, 8) –
G_synthesis/noise4 – (1, 1, 16, 16) –
G_synthesis/noise5 – (1, 1, 16, 16) –
G_synthesis/noise6 – (1, 1, 32, 32) –
G_synthesis/noise7 – (1, 1, 32, 32) –
G_synthesis/noise8 – (1, 1, 64, 64) –
G_synthesis/noise9 – (1, 1, 64, 64) –
G_synthesis/noise10 – (1, 1, 128, 128) –
G_synthesis/noise11 – (1, 1, 128, 128) –
G_synthesis/noise12 – (1, 1, 256, 256) –
G_synthesis/noise13 – (1, 1, 256, 256) –
G_synthesis/noise14 – (1, 1, 512, 512) –
G_synthesis/noise15 – (1, 1, 512, 512) –
G_synthesis/noise16 – (1, 1, 1024, 1024) –
G_synthesis/noise17 – (1, 1, 1024, 1024) –
images_out – (?, 3, 1024, 1024) –
— — — —
Total 26219627

 

这就说明程序运行了,此时到你的C:\Users\Administrator\stylegan-master\results文件夹下,就能看到生成的照片了

恭喜你完成了stylegan的运行第一步!

 

注意:如果需要生成不同人的照片,使用编译器打开:pretrained_example.py 文件

第34行  rnd = np.random.RandomState(8)

其中()内的内容代表一个扰动因子,输入不同的数字,执行之后会生成不同的照片,可以试试!

PS:个人未来安排:接下来第二步研究老婆头像生成的算法(已完成)
关于如何生成动漫头像  请看这篇https://www.gongyesheji.org/?p=963

训练自己的数据集请看这篇文章:

如何使用stylegan训练自己的照片数据集

Show 46 Comments

46 Comments

  1. wwt

    你好博主,我想问一下这个是什么情况
    Traceback (most recent call last):

    File “”, line 561, in
    model.train()

    File “”, line 337, in train
    a, b, c = self.train_step(self.im.get_batch(BATCH_SIZE).astype(‘float32’), style, nImage(BATCH_SIZE), self.gp_weight)

    File “E:\xinjianwenjianjia\xiazai\style-gan\datagen.py”, line 139, in get_batch
    idx = np.random.randint(0, self.images.shape[0] – 1, num)

    File “mtrand.pyx”, line 745, in numpy.random.mtrand.RandomState.randint

    File “_bounded_integers.pyx”, line 1346, in numpy.random._bounded_integers._rand_int32

    ValueError: low >= high

  2. 在又一年后,我终于搞好了自己的一个模型,谢谢博主了

  3. leo

    2019年的1年后的现在,我又找到你了

    • 哈哈哈哈我也好几次重装完系统以后回来看自己写的这篇文章……

  4. Cloud

    博主您好!感谢您的详细教程!请问您文章里说CUDNN用7.5的,但是分享的为什么是7.6.4的呀(我下了7.6.4也生成成功了!

    • 可能是因为这个网址连接的网页自动更新为最新版本了!不过能支持就好啦,新版本一般都对下兼容

  5. fei

    Downloading https://drive.google.com/uc?id=1MEGjdvVpUsu1jB4zrXZN7Y4kBBOzizDQ ………… failed
    Traceback (most recent call last):
    File “pretrained_example.py”, line 47, in
    main()
    File “pretrained_example.py”, line 24, in main
    with dnnlib.util.open_url(url, cache_dir=config.cache_dir) as f:
    File “E:\StyleGAN\stylegan-master\dnnlib\util.py”, line 378, in open_url
    raise IOError(“Google Drive quota exceeded”)
    OSError: Google Drive quota exceeded

    楼主请问一下这个报错要怎么解决,如果我手动下载了pkl文件应该放在哪个文件夹?

    • emmm,咱也不是很清楚应该放在哪里,最好是放在当前的运行目录下吧~

    • ggc

      解决了嘛?我也遇到这个问题

    • iuiu

      你好,请问这个问题解决了吗,我也遇到了

  6. nuonuo

    您好 博主
    File “C:\Users\nucky\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\framework\tensor_shape.py”, line 632, in as_dimension
    return Dimension(value)
    File “C:\Users\nucky\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\framework\tensor_shape.py”, line 185, in __init__
    self._value = int(value)
    TypeError: int() argument must be a string, a bytes-like object or a number, not ‘Tensor’

    这个bug得怎么解决啊

  7. JS

    到输入python pretrained_example.py这一步的时候,出现downloading….的错误

  8. 喵帕西

    博主你好 窝遇到了如下问题 呜呜呜 CUDA加速有点不会操作
    cudnn\bin\cudnn64_5.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin\
    cudnn\include\cudnn.h to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include\
    cudnn\lib\x64\cudnn.lib to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64\
    我的c盘文件夹下 没有NVIDIA GPU Computing Toolkit 窝自己创建了一个 目前无法还是不行
    2020-03-05 08:37:19.094314: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘cudart64_101.dll’; dlerror: cudart64_101.dll not found
    2020-03-05 08:37:19.101542: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
    Traceback (most recent call last):
    File “01.py”, line 7, in
    import dnnlib.tflib as tflib
    File “C:\Users\用户名\stylegan-master\dnnlib\tflib\__init__.py”, line 8, in
    from . import autosummary
    File “C:\Users\用户名\stylegan-master\dnnlib\tflib\autosummary.py”, line 31, in
    from . import tfutil
    File “C:\Users\用户名\stylegan-master\dnnlib\tflib\tfutil.py”, line 34, in
    def shape_to_list(shape: Iterable[tf.Dimension]) -> List[Union[int, None]]:
    AttributeError: module ‘tensorflow’ has no attribute ‘Dimension’

    • 你的Program Files里面如果没有NVIDIA GPU Computing Toolkit说明你的CUDA没有安装成功的!或者是你修改了CUDA的安装目录,这就需要将文件放到你CUDA的安装路径下了,如果没有安装成功,这有可能是因为显卡驱动版本或者你安装时候错误取消了这个模块的勾选造成的,建议重新安装一遍CUDA,使用自定义安装模式,取消gefore experience和声卡驱动没关系,但是一定要安装CUDA套件

  9. XI

    博主您好,我按照您的教程一步步执行,到运行程序的时候出现了如下的错误,望您能指点下?
    AttributeError: module ‘tensorflow’ has no attribute ‘Dimension’

    • 我感觉这是tensorflow没有安装好或者没有启用,建议先使用一段简单的代码检查tensorflow是否安装成功,再运行stylegan

    • 雪竹霜月

      虽然你可能已经知道原因了,但是我还是要说一下,导致这个原因的问题是你安装了TensorFlow 2.0版,博主提供的训练模型需要使用TensorFlow 1.13.1
      TensorFlow 2.0的一些用法有变化的。

  10. yoooooomu

    博主我挂了代理但是还是下到一半就报错了

    • 作为一个学设计的学生。。。。我头脑中第一反应是ps合成一下。。。但是我感觉用python的图形相关插件是不是也可以批量生成一个列表。。。设置一个画布然后摆上每一张图这样orz

  11. fernando

    博主你知不知道什么能用的代理呀我这最后一步实在下不下来

  12. fwj7

    耗了好几天,终于按着这篇文章装好了,网上其他的要么python版本3.6,要么系统不一样

  13. 徐帅

    cudnn是7.5还是10???

  14. smile

    博主雷猴,为什么我activate tensorflow-gpu之后无法CD切换去其他目录呢,是因为anaconda默认目录的原因嘛

    • 我刚刚尝试了一下,激活环境之后,应该是可以cd切换的,你看看是不是打错了路径呀,或者斜杠打反了?

    • SPL

      由 C: 轉去 D: 只要打 d:, 不用 cd d:
      然後 (tensorflow-gpu) D: cd

  15. 111asd

    博主您好,我按照您的教程一步步执行,到运行程序的时候出现了如下的错误,望您能指点下?
    Traceback (most recent call last):
    File “F:\ANAconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”, line 58, in
    from tensorflow.python.pywrap_tensorflow_internal import *
    File “F:\ANAconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line 28, in
    _pywrap_tensorflow_internal = swig_import_helper()
    File “F:\ANAconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line 24, in swig_import_helper
    _mod = imp.load_module(‘_pywrap_tensorflow_internal’, fp, pathname, description)
    File “F:\ANAconda\envs\tensorflow-gpu\lib\imp.py”, line 242, in load_module
    return load_dynamic(name, filename, file)
    File “F:\ANAconda\envs\tensorflow-gpu\lib\imp.py”, line 342, in load_dynamic
    return _load(spec)
    ImportError: DLL load failed: 找不到指定的模块。

    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
    File “pretrained_example.py”, line 15, in
    import dnnlib.tflib as tflib
    File “C:\Users\hp\stylegan\dnnlib\tflib\__init__.py”, line 8, in
    from . import autosummary
    File “C:\Users\hp\stylegan\dnnlib\tflib\autosummary.py”, line 27, in
    import tensorflow as tf
    File “F:\ANAconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py”, line 24, in
    from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
    File “F:\ANAconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\__init__.py”, line 49, in
    from tensorflow.python import pywrap_tensorflow
    File “F:\ANAconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”, line 74, in
    raise ImportError(msg)
    ImportError: Traceback (most recent call last):
    File “F:\ANAconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py”, line 58, in
    from tensorflow.python.pywrap_tensorflow_internal import *
    File “F:\ANAconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line 28, in
    _pywrap_tensorflow_internal = swig_import_helper()
    File “F:\ANAconda\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py”, line 24, in swig_import_helper
    _mod = imp.load_module(‘_pywrap_tensorflow_internal’, fp, pathname, description)
    File “F:\ANAconda\envs\tensorflow-gpu\lib\imp.py”, line 242, in load_module
    return load_dynamic(name, filename, file)
    File “F:\ANAconda\envs\tensorflow-gpu\lib\imp.py”, line 342, in load_dynamic
    return _load(spec)
    ImportError: DLL load failed: 找不到指定的模块。

    Failed to load the native TensorFlow runtime.

    • 你这个应该是tensorflow没有安装好,或者没有使用cuda加速的tensorflow-gpu?重新检查一遍吧~

      • 博主,我运行也产生这样的问题,博主能不能指导一下具体解决办法啊?我的基础有点差。

        • 不好意思我也不知道准确的解决办法哦,我猜应该是tensorflow没装好的问题

        • 匿名

          我也遇到了同样的问题,请问有解决嘛

  16. 暗霜

    想试试GAN生成人像用在游戏里 看过很多视频和帖子都是高大上空讲一堆 内行没必要看 外行看了没用

    这一篇感觉操作性非常强 回去试试 感谢作者 希望我也可以搭建出来

    • 我觉得游戏角色设计是挺好的方向,但目前还没搞明白如何用对抗神经网络训练自己的数据集。大佬们使用的数据集基本都是百万量级的,且使用高端计算卡都需要十几天。
      如果公司报销的话,可以考虑付费用Google等公司提供的计算服务来算数据集~

  17. 子七

    楼主,一直出现Cannot assign a device for operation Gs怎么解决呀

  18. js

    [WinError 10061] 由于目标计算机积极拒绝,无法连接。楼主

    • 是执行pip的时候出现的?是不是没有挂代理呀……不过我印象里某SS被封端口以后好像会出这个提示……233

  19. Ric'y

    朋友 靠谱, 其他的博客都是些什么garbage

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注