DCGAN-tensorflow使用经历

隐身守侯 提交于 2019-12-14 05:41:39

DCGAN-tensorflow使用经历

原网站:https://github.com/carpedm20/DCGAN-tensorflow

1.使用官方训练集

坑:

命令:python download.py mnist celebA

celebA数据库下载,众所周知的原因,需要自己想办法。
mnist在下载好一个文件之后报错,不多说直接留下网盘自己下载

链接:https://pan.baidu.com/s/13FlJTDrV4tAf_vl8N1GzCA
提取码:x7ww

下载之后四个文件

train-images-idx3-ubyte.gz
train-labels-idx1-ubyte.gz
t10k-images-idx3-ubyte.gz
t10k-labels-idx1-ubyte.gz

下载好之后的文件夹关系是:
DCGAN-tensorflow-master>data>celebA,mnist
celebA>一堆人脸图片
mnist>四个文件

这里又遇到一个坑,解包之后文件名字“-”自动变成“.”
例如:train-images-idx3.ubyte.gz
可能是我使用windows,7z解压的锅。
四个都分别手动改回来例如train-images-idx3-ubyte之后成功。

命令:python main.py --dataset mnist --input_height=28 --output_height=28 --train

Python报错 module ‘scipy.misc’ has no attribute ‘imsave’
是因为scipy版本过高,pip uninstall scipy卸载scipy,然后conda install scipy==1.2.0,成功。

2.使用自定义数据集(二次元头像自动生成)

参考:https://blog.csdn.net/mozf881/article/details/83592977

命令

python main.py --dataset faces --input_height 96 --input_width 96 --output_height 48 --output_width 48 --crop --train --epoch 20 --input_fname_pattern "*.jpg"

坑:
问题全部出在:utils.py这个文件

TypeError: Cannot handle this data type

line 94, in center_crop()
im = Image.fromarray(x[j:j+crop_h, i:i+crop_w])
改成:
im = Image.fromarray(np.uint8(x[j:j+crop_h, i:i+crop_w]))

NameError: name ‘PIL’ is not defined

在上面import PIL,不解释了

TypeError: data type not understood

line 95, in center_crop()
return np.array(im.resize([resize_h, resize_w]), PIL.Image.BILINEAR)
改成:
return np.array(im.resize([resize_h, resize_w], PIL.Image.BILINEAR))

PIL.Image.BILINEAR应该是im.resize的参数才对,括号位置有问题。

UnboundLocalError: local variable ‘im’ referenced before assignment

line 105, in transform()
return np.array(im.resize([resize_h, resize_w]), PIL.Image.BILINEAR)/127.5 - 1.

改成:
return cropped_image/127.5 - 1.

明明上面定义了cropped_image变量却没用。

改了这些就成功运行了

训练100个周期之后的效果:
100周期

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!