keras运行gan的几个bug解决

A:

1.原因:在跑GAN时由于keras无法使用tensorflow的LeakyReLU,可能没有此函数,

2.step:
(1)
自定义添加到models.py里:
def LeakyReLU(x, leak=0.2, name="lrelu")
    with tf.variable_scope(name):
        f1 = 0.5 * (1 + leak)
        f2 = 0.5 * (1 - leak)
        return f1 * x + f2 * abs(x)

(2)
   from keras.layers import Lambda
    x = Lambda(lambda x: LeakyReLU(x))(x)


说明:没有第二步,会报错:
AttributeError: 'Tensor' object has no attribute '_keras_history'


B:

GANs_N_Roses:https://github.com/Naresh1318/GANs_N_Roses
运行该github时有
ValueError: Variable d_h0_conv/w/Adam/ does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=None in VarScope?

说明:
tensorflow0.12只能 使用tf.train.GradientDescentOptimizer
用tf.train.AdamOptimizer或者其他的都会报错

C:

GANs_N_Roses:https://github.com/Naresh1318/GANs_N_Roses
运行该github时有
报错
OSError: [WinError 123] 文件名、目录名或卷标语法不正确。: 'Results/roses/2018-01-30 18:00:30.897494_100_12_30000_0.0002_0.5'

step

注释掉
results_folder = '{0}_{1}_{2}_{3}_{4}_{5}' \
        .format(datetime.datetime.now(), mc.Z_DIM, mc.BATCH_SIZE, mc.N_ITERATIONS, mc.LEARNING_RATE, mc.BETA_1)
改成
results_folder='cctv'
说明:文件名又臭又长会不允许


D:

KERAS-DCGAN
https://github.com/jacobgil/keras-dcgan

跑DCGAN时遇到到问题
       源码
        y_pred = self.f_dis(x_true)   #真x预测
        x_fake = self.f_gen(z_sample)  #噪音生成假图
        y_fake = self.f_dis(x_fake)  #假x预测
报错
第一个
ValueError: Variable batch_normalization_8/moving_mean/biased already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:
第二个
Exception ignored in: >
Traceback (most recent call last):
  File "D:\ProgramData\Anaconda3\envs\py35\lib\site-packages\tensorflow\python\client\session.py", line 595, in __del__
TypeError: 'NoneType' object is not callable

说明:上述三个每个都有相同的biased,冲突了,因此得在各自域起个名字,使得各自biased在各自己域分开

step:

with tf.variable_scope("y_pred",reuse=None):
       y_pred = self.f_dis(x_true)
with tf.variable_scope("x_fake", reuse=None):
       x_fake = self.f_gen(z_sample)
with tf.variable_scope("y_fake", reuse=None):
        y_fake = self.f_dis(x_fake)







你可能感兴趣的:(gan)