python 3.5.8
2.创建虚拟环境python -m venv D:DcganPython35TF3.安装环境 先激活虚拟环境
D:DcganPython35TFscripts>activate安装环境
使用中国科技大学的源进行安装
pip install -r dcgan.txt -i https://pypi.mirrors.ustc.edu.cn/simple/
dcgan.txt
Django==2.2.24 image==1.5.33 numpy==1.18.5 opencv-python==4.4.0.42 Pillow==7.2.0 protobuf==3.17.2 pytz==2021.1 scipy==1.2.1 six==1.16.0 sqlparse==0.4.1 tensorflow==0.12.1 tqdm==4.61.04.下载DCGAN-tensorflow
git clone https://github.com/carpedm20/DCGAN-tensorflow.git
或者
git clone https://gitee.com/jy13101314/DCGAN-tensorflow.git5.下载celebA
下载数据集celebA,打开下述页面下载img_align_celeba.zip
http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html
解压数据到datacelebA文件夹,目录结构为:
6.修改代码DCGAN-tensorflowdatacelebA 0001.jpg
main.py
70行
with open(os.path.join(FLAGS.out_dir, 'FLAGS.json'), 'w') as f:
flags_dict = {k:FLAGS[k].value for k in FLAGS}
json.dump(flags_dict, f, indent=4, sort_keys=True, ensure_ascii=False)
改为:
with open(os.path.join(FLAGS.out_dir, 'FLAGS.json'), 'w') as f:
#flags_dict = {k:FLAGS[k].value for k in FLAGS}
#json.dump(flags_dict, f, indent=4, sort_keys=True, ensure_ascii=False)
json.dump(flags.FLAGS.__flags, f, indent=4, sort_keys=True, ensure_ascii=False)
utils.py
新增: import PIL
94行 im = Image.fromarray(x[j:j+crop_h, i:i+crop_w]) return np.array(im.resize([resize_h, resize_w]), PIL.Image.BILINEAR) 改为 im = Image.fromarray(np.uint8(x[j:j+crop_h, i:i+crop_w])) #return np.array(im.resize([resize_h, resize_w]), PIL.Image.BILINEAR) return np.array(im.resize([resize_h, resize_w], PIL.Image.BILINEAR))
104行 im = Image.fromarray(image[j:j+crop_h, i:i+crop_w]) return np.array(im.resize([resize_h, resize_w]), PIL.Image.BILINEAR)/127.5 - 1. 改为 im = Image.fromarray(np.uint8(image[j:j+crop_h, i:i+crop_w])) #return np.array(im.resize([resize_h, resize_w]), PIL.Image.BILINEAR)/127.5 - 1. return cropped_image/127.5 - 1.7.运行
python main.py



