偶然的一次机会帮别人调程序,发现DCGAN在1080ti上占用显存只有600M左右,我想是不是可以笔记本上跑一下,本着玩一玩的心态,跑了一下,虽然很慢大约30s左右一张图片,但是可以当做练手的。先贴一下古董笔记本cpu。
因为之前跑过一些python程序,opencv,svm,爬虫啥的,电脑上有python2.7和python3.6。DCGAN在python2.7和python3.6是都可以跑通的。
cpu版本的tensorflow安装
使用的是原生pip安装,官网写的很清楚,window下只支持python3.5.x 64位和python3.6.x 64位,python3附带有pip3软件包管理器,可以使用此程序安装cpu版本的tensorflow。
输入以下命令:
C:\> pip3 install --upgrade tensorflow
验证安装
可以从shell中调用python,如下所示:
$ python
在 Python 交互式 shell 中输入以下几行简短的程序代码:
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
如果系统输出以下内容,就说明您可以开始编写 TensorFlow 程序了:
Hello, TensorFlow!
依赖库配置:
输入命令
pip3 install scipy
.............
pip3 install scikit-image
我只配置了两个依赖库scipy和scikit-image。
代码下载https://github.com/tensorlayer/dcgan
下载好后,cmd需要进入程序所在目录。
首先下载数据集到 dcgan-master/data/celebA
:
$ python download.py celebA [202599 face images]
接下来训练gan
$ python main.py
可能报错:
$ python main.py
/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
Traceback (most recent call last):
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 166, in _parse
return self.parser.parse(argument)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_argument_parser.py", line 152, in parse
val = self.convert(argument)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_argument_parser.py", line 268, in convert
type(argument)))
TypeError: Expect argument to be a string or int, found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 23, in
flags.DEFINE_integer("train_size", np.inf, "The size of train images [np.inf]")
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/tensorflow/python/platform/flags.py", line 58, in wrapper
return original_function(*args, **kwargs)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_defines.py", line 315, in DEFINE_integer
DEFINE(parser, name, default, help, flag_values, serializer, **args)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_defines.py", line 81, in DEFINE
DEFINE_flag(_flag.Flag(parser, serializer, name, default, help, **args),
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 107, in __init__
self._set_default(default)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 196, in _set_default
self.default = self._parse(value)
File "/home/ly/anaconda3/envs/learning/lib/python3.6/site-packages/absl/flags/_flag.py", line 169, in _parse
'flag --%s=%s: %s' % (self.name, argument, e))
absl.flags._exceptions.IllegalFlagValueError: flag --train_size=inf: Expect argument to be a string or int, found
解决办法:
在 main.py中的第22行,把
flags.DEFINE_integer("train_size", np.inf, "The size of train images [np.inf]")
改成
flags.DEFINE_float("train_size", np.inf, "The size of train images [np.inf]")
然后就可以正常运行了。这个跑通之后建议跑另外一个dcgan,比较详细。 https://github.com/carpedm20/DCGAN-tensorflow