如何将移动平均线应用于急切张量

时间:2018-06-06 07:47:36

标签: python tensorflow

这是一个从cnn获取损失和评估的函数。

def tower_loss_and_eval(images, labels, train_phase, reuse=None, cpu_variables=False):
    with tf.variable_scope('inference', reuse=reuse):
        logits = net.inference(images, train_phase, cpu_variables=cpu_variables)
    losses = net.losses(logits, labels)
    total_loss = tf.add_n(losses, name='total_loss')
    loss_averages = tf.train.ExponentialMovingAverage(0.99, name='avg')
    loss_averages_op = loss_averages.apply(losses + [total_loss])

    for l in losses + [total_loss]:
        loss_name = l.op.name
        tf.summary.scalar(loss_name + ' (raw)', l)
        tf.summary.scalar(loss_name, loss_averages.average(l))

    with tf.control_dependencies([loss_averages_op]):
        total_loss = tf.identity(total_loss)
    total_loss = tf.identity(total_loss)

    evaluation = net.evaluation(logits, labels)
    return total_loss, evaluation

它引发了AttributeError:eager Tensors不支持op。

列表中有两个急切的张量'loss + [total_loss]'。 它们都是tf.Tensor(2.5177855,shape =(),dtype = float32)。 我想知道如何更改代码以实现应用操作。

0 个答案:

没有答案