在tens中处理损失和优化步骤之前的模型(预测)输出

2024-09-26 05:00:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个模型自动编码器,我想获取y_预测值,然后在丢失前返回;优化器步骤

with tf.device('/gpu:'+GPU0):
    ################################ ae loss
    Y_ = tf.reshape(self.Y, shape=[-1, 64 ** 3])
    Y_pred_modi_ = tf.reshape(self.D_1_Y, shape=[-1, 64 ** 3])
    w = 0.85
    self.aeu_loss = tf.reduce_mean(
        -tf.reduce_mean(w * Y_ * tf.log(Y_pred_modi_ + 1e-8), reduction_indices=[1]) -
        tf.reduce_mean((1 - w) * (1 - Y_) * tf.log(1 - Y_pred_modi_ + 1e-8), 
                       reduction_indices=[1]))
    self.total_loss=self.aeu_loss


    #################################  optimizer


with tf.device('/gpu:'+GPU0):
    aeu_var = [var for var in tf.trainable_variables() if var.name.startswith('aeu_2')]
    print(aeu_var)
    #dis_var = [var for var in tf.trainable_variables() if var.name.startswith('dis')]

    self.aeu_g_optim = tf.train.AdamOptimizer(learning_rate=0.0001, beta1=0.9, beta2=0.999,
                       epsilon=1e-8).minimize(self.total_loss, var_list=aeu_var)

在丢失之前,我想取Y_pred_modi_值处理它,然后返回它


Tags: selfreducegpuvardevicetfwithmean