WGAN-GP代码修改

项目地址:https://github.com/igul222/improved_wgan_training
用的是gan_64x64.py。

问题1

NameError: name 'xrange' is not defined

解决方法:把所有xrange改为range就行。

问题2

Tensorflow Type Error: Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64

解决方法:将所有shape的数据都转为int型就行了。详情https://blog.csdn.net/fu6543210/article/details/79945089

问题3

AttributeError: 'generator' object has no attribute 'next'

解决方法:原因是在python 3.x中 generator(有yield关键字的函数则会被识别为generator函数)中的next变为__next__了,next是python 3.x以前版本中的方法,所以把f.next()改为f.__next__()就行了。详情:https://blog.csdn.net/tenderzhe/article/details/73480561

问题4

TypeError: 'range' object does not support item assignment

原因:python3中range() 返回的是“range object”,而不是实际的list 值。
解决办法:将上面例子的代码: a = range(0,N)改为a = list(range(0,N)) 就好啦!
详情:https://blog.csdn.net/tenderzhe/article/details/73480561

问题5

    Traceback (most recent call last):
  File "gan_64x64.py", line 590, in 
    lib.save_images.save_images(_x_r.reshape((int(BATCH_SIZE/N_GPUS), 3, 64, 64)), 'samples_groundtruth.png')
  File "D:\JupyterWorkSpace\improved_wgan_training-master\tflib\save_images.py", line 36, in save_images
    img[j*h:j*h+h, i*w:i*w+w] = x
    TypeError: slice indices must be integers or None or have an __index__ method

原因:源程序中一直用/来进行两数相除,而python3中slice indices不能是小数,然而python3中" / “就一定表示 浮点数除法,返回浮点结果;” // "表示整数除法。
解决办法:把“/”换成“//”,或者在小数外加一个int()
详情:https://blog.csdn.net/data8866/article/details/62884210/

问题6

Traceback (most recent call last):
  File "gan_64x64.py", line 629, in 
    lib.plot.flush()
  File "D:\JupyterWorkSpace\improved_wgan_training-master\tflib\plot.py", line 25, in flush
    prints.append("{}\t{}".format(name, np.mean(vals.values())))
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py", line 2957, in mean
    out=out, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\_methods.py", line 82, in _mean
    ret = ret / rcount
TypeError: unsupported operand type(s) for /: 'dict_values' and 'int'

原因:The above line is correct in Python2 where dict.values() returns a list, but is not in Python3 where it returns a special type dict_values.
解决办法:把prints.append("{}\t{}".format(name, np.mean(vals.values())))换成prints.append("{}\t{}".format(name, np.mean(list(vals.values()))))
详情:https://stackoverflow.com/questions/49312282/typeerror-unsupported-operand-types-for-dict-values-and-dict-values

问题7

Traceback (most recent call last):
  File "gan_64x64.py", line 629, in 
    lib.plot.flush()
  File "D:\JupyterWorkSpace\improved_wgan_training-master\tflib\plot.py", line 28, in flush
    x_vals = np.sort(_since_beginning[name].keys())
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py", line 847, in sort
    a.sort(axis=axis, kind=kind, order=order)
numpy.core._internal.AxisError: axis -1 is out of bounds for array of dimension 0

原因:跟问题5同理
解决办法:把x_vals = np.sort(_since_beginning[name].keys())换成x_vals = np.sort(list(_since_beginning[name].keys()))

你可能感兴趣的:(GAN)