ghttps://github.com/carpedm20/DCGAN-tensorflow
源码链接
链接:https://pan.baidu.com/s/1GLVmlohUaQcjnxj33UUAUg
提取码:gmo7
--来自百度网盘超级会员V3的分享
修改后的代码
链接:https://pan.baidu.com/s/1748yptqZYZcZ6MsBCoz_lg
提取码:biha
--来自百度网盘超级会员V3的分享
数据集
这是我的环境 (3.7)
PS C:\Users\pc\Desktop\DCGAN-tensorflow-master> pip list
Package Version
---------------------------- ---------
absl-py 1.1.0
astor 0.8.1
astunparse 1.6.3
baidu-aip 2.2.18.0
cachetools 5.2.0
certifi 2021.10.8
charset-normalizer 2.0.12
colorama 0.4.5
flatbuffers 1.12
gast 0.2.2
google-auth 2.9.0
google-auth-oauthlib 0.4.6
google-pasta 0.2.0
grpcio 1.47.0
h5py 3.7.0
idna 3.3
imageio 2.19.3
importlib-metadata 4.12.0
keras 2.9.0
Keras-Applications 1.0.8
Keras-Preprocessing 1.1.2
libclang 14.0.1
Markdown 3.3.7
MouseInfo 0.1.3
numpy 1.21.6
oauthlib 3.2.0
opencv-python 4.6.0.66
opt-einsum 3.3.0
packaging 21.3
Pillow 9.1.1
pip 22.1.2
protobuf 3.19.4
pyasn1 0.4.8
pyasn1-modules 0.2.8
PyAutoGUI 0.9.53
PyGetWindow 0.0.9
PyMsgBox 1.0.9
pyparsing 3.0.9
pyperclip 1.8.2
pypiwin32 223
PyRect 0.2.0
PyScreeze 0.1.28
pytweening 1.0.4
pywin32 304
requests 2.27.1
requests-oauthlib 1.3.1
rsa 4.8
scipy 1.7.3
setuptools 62.3.2
six 1.16.0
tensorboard 1.14.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit 1.8.1
tensorflow 1.14.0
tensorflow-estimator 1.14.0
tensorflow-io-gcs-filesystem 0.26.0
termcolor 1.1.0
tqdm 4.64.0
typing_extensions 4.2.0
urllib3 1.26.8
Werkzeug 2.1.2
wheel 0.37.1
wrapt 1.14.1
zipp 3.8.0
首先我对图片做了一个resize
import os
from PIL import Image
def resize(old_path, new_path, size, resample):
"""
通过指定的resample方式调整old_path下所有的jpg图片为指定的size,并保存到new_path下
"""
if os.path.isdir(old_path):
for child in os.listdir(old_path):
if child.find('.jpg') > 0:
im = Image.open(old_path + child)
im_resized = im.resize(size=size, resample=resample)
if not os.path.exists(new_path):
os.makedirs(new_path)
print(child, 'resize successfully!')
im_resized.save(new_path + child, im.format)
child_path = old_path + child + '/'
resize(child_path, new_path, size, resample)
if __name__ == "__main__":
old_path = r'./DCGAN-tensorflow-master\data\licence/'
new_path = r'./DCGAN-tensorflow-master\data\1/'
size = (240, 80)
resample = Image.BILINEAR # 使用线性插值法重采样
resize(old_path, new_path, size, resample)
填好路径
开始训练
权重和图片在out
报错一:
主要原因 图片尺寸 写的不对。
未改
修改后
报错2:
训练中出现 one pic error!... 会导致图片无法保存
具体修改去看 我已经改好的utils.py 代码
我看网上有人这么改
把utils.py 里面的image_manifold_size替换了(没试过)
# def image_manifold_size(num_images):
# #manifold_h = int(np.floor(np.sqrt(num_images)))
# #manifold_w = int(np.ceil(np.sqrt(num_images)))
# manifold_w = int(16)
# manifold_h = int(num_images/16)
# assert manifold_h * manifold_w == num_images
# return manifold_h, manifold_w
建议
在main中 找到
flags.DEFINE_integer("batch_size", 1, "The size of batch images [64]") #batch_size大小,所谓的每次迭代的图像数量 当设为1的效果
设为16
设为64