张量标准化开关张量流

时间:2018-02-04 14:17:11

标签: tensorflow batch-normalization

这是一个自动编码器。

我的问题是我不知道如何设置"模式"让它分成"训练"和"测试"。

如果你们能给我一个例子,我很高兴:D

我可以使用全局变量或占位符来更改"模式" ?

我很高兴你能为我解答。

#batch normalization
def Batch_norm_en(Wx_plus_b, i):
    if mode == 1:
        fc_mean_en, fc_var_en = tf.nn.moments(Wx_plus_b, axes=[0, 1])
    else:
        fc_mean_en, fc_var_en = fc_mean_en, fc_var_en
    Wx_plus_b = tf.nn.batch_normalization(Wx_plus_b, fc_mean_en, fc_var_en, shift_en[i], scale_en[i], 10**(-3))
    return Wx_plus_b

def Batch_norm_de(Wx_plus_b, i):
    if mode == 1:
        fc_mean_de, fc_var_de = tf.nn.moments(Wx_plus_b, axes=[0, 1])
    else:
        fc_mean_de, fc_var_de = fc_mean_de, fc_var_de
    Wx_plus_b = tf.nn.batch_normalization(Wx_plus_b, fc_mean_de, fc_var_de, shift_de[i], scale_de[i], 10**(-3))
    return Wx_plus_b

#encoder data
def encoder_model(x):
    res = x
    for i in range(0, len(en_n_neurons)-1):
        Wx_plus_b = tf.matmul(res,W_en[i]) + b_en[i]
        Wx_plus_b = Batch_norm_en(Wx_plus_b, i)
        res = tf.nn.sigmoid(Wx_plus_b)
    return res

#decoder data
def decoder_model(x):
    res = x
    for i in range(0, len(de_n_neurons)-1):
        Wx_plus_b = tf.matmul(res,W_de[i]) + b_de[i]
        Wx_plus_b = Batch_norm_de(Wx_plus_b, i)
        res = tf.nn.sigmoid(Wx_plus_b)
    return res

0 个答案:

没有答案