栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

DCGAN-tensorflow环境搭建

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

DCGAN-tensorflow环境搭建

1.安装软件

python 3.5.8

2.创建虚拟环境
python -m venv D:DcganPython35TF
3.安装环境 先激活虚拟环境
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.0
4.下载DCGAN-tensorflow
git clone https://github.com/carpedm20/DCGAN-tensorflow.git

或者

git clone https://gitee.com/jy13101314/DCGAN-tensorflow.git
5.下载celebA

下载数据集celebA,打开下述页面下载img_align_celeba.zip

http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html

解压数据到dataceleb​​​​​​​A文件夹,目录结构为:

DCGAN-tensorflowdatacelebA0001.jpg

6.修改代码

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/272815.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号