是否可以将批量归一化的输出发送到下一层而不是激活输出?

时间:2019-04-16 17:20:43

标签: python tensorflow keras

我有一个带有两个输出的自动编码器,经过一些更改后,第一个输出应用作自动编码器下一部分的输入。我将代码放在这里,我对此代码在逻辑上是否正确感到有些困惑。在以下代码中,我在decoder部分中有一个输出,名为act11,是S形激活的输出,第二个输出在w extraction部分中,名为pred_W。我将bncv11而不是GaussianNoise馈入act11。我想知道这是正确的还是错误的?根据反向传播规则和网络结构可以做到这一点吗?我可以仅使用此代码act11=Activation('sigmoid',name='imageprim')(bncv11)中的激活输出作为模型的输出吗? 我所有的问题都与代码的这一部分有关:

decoded = Conv2D(1, (5, 5),  padding='same', name='decoder_output',dilation_rate=(2,2))(BNd) 
bncv11=BatchNormalization()(decoded)
act11=Activation('sigmoid',name='imageprim')(bncv11)
decoded_noise = GaussianNoise(0.5)(bncv11)

#----------------------w extraction------------------------------------
convw1 = Conv2D(64, (3,3), activation='relu', padding='same', name='conl1w',dilation_rate=(2,2))(decoded_noise)
watermark_extraction=Model(inputs=[image,wtm],outputs=[act11,pred_w])

我想知道上述基于深度学习的代码是否正确? 我只是在激活过程中使用act11进行输出,而在学习过程中使用bncv11进行进餐。

wtm=Input((28,28,1))
image = Input((28, 28, 1))
conv1 = Conv2D(64, (5, 5), activation='relu', padding='same', name='convl1e',dilation_rate=(2,2))(image)
conv2 = Conv2D(64, (5, 5), activation='relu', padding='same', name='convl2e',dilation_rate=(2,2))(conv1)
conv3 = Conv2D(64, (5, 5), activation='relu', padding='same', name='convl3e',dilation_rate=(2,2))(conv2)
BN=BatchNormalization()(conv3)
encoded =  Conv2D(1, (5, 5), activation='relu', padding='same',name='encoded_I',dilation_rate=(2,2))(BN)


add_const = Kr.layers.Lambda(lambda x: x[0] + x[1])
encoded_merged = add_const([encoded,wtm])

#-----------------------decoder------------------------------------------------
deconv1 = Conv2D(64, (5, 5), activation='relu', padding='same', name='convl1d',dilation_rate=(2,2))(encoded_merged)
deconv2 = Conv2D(64, (5, 5), activation='relu', padding='same', name='convl2d',dilation_rate=(2,2))(deconv1)
deconv3 = Conv2D(64, (5, 5), activation='relu',padding='same', name='convl3d',dilation_rate=(2,2))(deconv2)
deconv4 = Conv2D(64, (5, 5),  activation='relu',padding='same', name='convl4d',dilation_rate=(2,2))(deconv3)

BNd=BatchNormalization()(deconv3)

decoded = Conv2D(1, (5, 5),  padding='same', name='decoder_output',dilation_rate=(2,2))(BNd) 
bncv11=BatchNormalization()(decoded)
act11=Activation('sigmoid',name='imageprim')(bncv11)
decoded_noise = GaussianNoise(0.5)(bncv11)

#----------------------w extraction------------------------------------
convw1 = Conv2D(64, (3,3), activation='relu', padding='same', name='conl1w',dilation_rate=(2,2))(decoded_noise)
convw2 = Conv2D(64, (3, 3), activation='relu', padding='same', name='convl2w',dilation_rate=(2,2))(convw1)
convw3 = Conv2D(64, (3, 3), activation='relu', padding='same', name='conl3w',dilation_rate=(2,2))(convw2)
convw4 = Conv2D(64, (3, 3), activation='relu', padding='same', name='conl4w',dilation_rate=(2,2))(convw3)
convw5 = Conv2D(64, (3, 3), activation='relu', padding='same', name='conl5w',dilation_rate=(2,2))(convw4)
convw6 = Conv2D(64, (3, 3), activation='relu', padding='same', name='conl6w',dilation_rate=(2,2))(convw5)
pred_w = Conv2D(1, (1, 1), activation='sigmoid', padding='same', name='reconstructed_W',dilation_rate=(2,2))(convw6)  

watermark_extraction=Model(inputs=[image,wtm],outputs=[act11,pred_w])

0 个答案:

没有答案