In Tensorflow I can assign names to operations and tensors to retrieve them later. For example in one function I can do
input_layer=tf.placeholder(tf.float32, shape= [None,300], name='input_layer')
And then in another function later, I can do
input_layer=get_tensor_by_name('input_layer:0')
I came to believe that this is handy for making my tf code as modular as possible.
I would like to be able to do the same with my loss but how can I assign a custom name to that operation? The problem is that the build in loss functions (e.g., tf.losses.mean_squared_error) do not have a parameter for the name (in contrast to tf.placeholder, tf.variable and so on).
The way I refer to my loss at the moment is
tf.get_collection(tf.GraphKeys.LOSSES)[-1]
Am I missing something obvious?
question from:
https://stackoverflow.com/questions/65648424/loss-operation-in-tensorflow 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…