-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Description
Wanted to add SN layers as described, added SpectralNormalizationKeras.py to the respective dir. However, the layer could not be integrated. Here the respective parts of code
from SpectralNormalizationKeras import DenseSN, ConvSN2D
(...)
def build_critic(self, spectral_normalization=True):
model = Sequential()
model.add(ConvSN2D(16, kernel_size=3, strides=2,kernel_initializer='glorot_uniform', input_shape=self.img_shape, padding="same"))
model.add(LeakyReLU(alpha=0.2))
model.add(Dropout(0.25))
model.add(ConvSN2D(32, kernel_size=3, strides=2,kernel_initializer='glorot_uniform', padding="same"))
model.add(ZeroPadding2D(padding=((0,1),(0,1))))
model.add(BatchNormalization(momentum=0.8))
model.add(LeakyReLU(alpha=0.2))
model.add(Dropout(0.25))
model.add(ConvSN2D(64, kernel_size=3, strides=2,kernel_initializer='glorot_uniform', padding="same"))
model.add(BatchNormalization(momentum=0.8))
model.add(LeakyReLU(alpha=0.2))
model.add(Dropout(0.25))
model.add(ConvSN2D(128, kernel_size=3, strides=1,kernel_initializer='glorot_uniform',padding="same"))
model.add(BatchNormalization(momentum=0.8))
model.add(LeakyReLU(alpha=0.2))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(DenseSN(1,kernel_initializer='glorot_uniform'))
model.summary()
img = Input(shape=self.img_shape)
validity = model(img)
return Model(img, validity)
Here the error call:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-24-da7bad03b7a7> in <module>
1 if __name__ == '__main__':
----> 2 wgan = WGANGP()
3 wgan.train(epochs=30001, batch_size=256, sample_interval=1500)
<ipython-input-23-9f58d066c64d> in __init__(self)
27 # Build the generator and critic
28 self.generator = self.build_generator()
---> 29 self.critic = self.build_critic()
30
31 #-------------------------------
<ipython-input-23-9f58d066c64d> in build_critic(self, spectral_normalization)
141 model = Sequential()
142
--> 143 model.add(ConvSN2D(16, kernel_size=3, strides=2,kernel_initializer='glorot_uniform', input_shape=self.img_shape, padding="same"))
144 model.add(LeakyReLU(alpha=0.2))
145 model.add(Dropout(0.25))
~\Anaconda3\envs\Tensorflow\lib\site-packages\tensorflow\python\keras\engine\sequential.py in add(self, layer)
126 raise TypeError('The added layer must be '
127 'an instance of class Layer. '
--> 128 'Found: ' + str(layer))
129 self.built = False
130 if not self._layers:
TypeError: The added layer must be an instance of class Layer. Found: <SpectralNormalizationKeras.ConvSN2D object at 0x000001BF340526D8>
Lots of thanks in advance for any suggestion of how to overcome this.
Metadata
Metadata
Assignees
Labels
No labels