SpectralNormalization
classkeras.layers.SpectralNormalization(layer, power_iterations=1, **kwargs)
对目标层的权重执行谱归一化.
该包装器通过约束权重的谱范数来控制层的Lipschitz常数,这可以稳定GAN的训练.
参数:
layer: 一个keras.layers.Layer
实例,
具有kernel
(例如Conv2D
, Dense
...)
或embeddings
属性(Embedding
层).
power_iterations: int, 归一化期间的迭代次数.
**kwargs: 基础包装器关键字参数.
示例:
>>> x = np.random.rand(1, 10, 10, 1)
>>> conv2d = SpectralNormalization(keras.layers.Conv2D(2, 2))
>>> y = conv2d(x)
>>> y.shape
(1, 9, 9, 2)
>>> x = np.random.rand(1, 10, 10, 1)
>>> dense = SpectralNormalization(keras.layers.Dense(10))
>>> y = dense(x)
>>> y.shape
(1, 10, 10, 10)
参考: