简体   繁体   中英

how do I activate Gaussian noise layer during test in keras?

I use Gaussian noise layer in my.network in keras, but I think it only works during training and it is inactive during the test phase. is it any way to activate it during testing or not? if I want to show the output of this layer during the train, what should I do? I also have a question about cropping2D in Keras. if I need random cropping that crops output of a layer in a different location, what should I do? because Cropping2D usually crop the center of the image. Thanks.

image = Input((28, 28, 1))
conv1 = Conv2D(64, (5, 5),padding='same', name='convl1e',dilation_rate=(2,2))(image)
bncv1=BatchNormalization()(conv1)
act1=Activation('relu')(bncv1)
decoded_noise = GaussianNoise(0.5)(act1)
#decoded_noise=Cropping2D(cropping=(6,6))(act1)#16
pred_w = Conv2D(1, (1, 1),padding='same', name='reconstructed_W',dilation_rate=(2,2))(decoded_noise)
bncv18=BatchNormalization()(pred_w)
act18=Activation('sigmoid', name='wprim')(bncv18)  
img_extraction=Model(inputs=image,outputs=act18)

You could create new class base on GaussianNoise with only minor modifications. You only need to adjust the call function slightly.

class AlwaysActiveGaussianNoise(GaussianNoise):

    def call(self, inputs, training=None):
        def noised():
            return inputs + self._random_generator.random_normal(
                shape=tf.shape(inputs),
                mean=0.0,
                stddev=self.stddev,
                dtype=inputs.dtype,
            )

         return noised()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM