2017-10-18 1 views
2

summary을 실행하기 전에 update_op이 실행되기를 원합니다. 가끔은 그냥 tf.summary을 만들고, 모든 것이 잘 작동하지만 때로는 더 멋진 것들을하고 싶지만 여전히 같은 컨트롤 의존성을 가지고 있습니다. 작동하지 않는Tensorflow에 제어 종속성을 추가하는 방법

코드 :

with tf.control_dependencies([update_op]): 
    if condition: 
     tf.summary.scalar('summary', summary) 
    else: 
     summary += 0 

문제를 작동

with tf.control_dependencies([update_op]): 
    if condition: 
     tf.summary.scalar('summary', summary) 
    else: 
     summary = summary 

나쁜 해킹 제어 의존성이 무시되도록 summary=summary는, 새로운 노드를 작성하지 않습니다.


나는이 방법에 대한 좋은 제안이있을 것이라고 확신합니다. :-)

+0

'tf.identity (summary)'가 작동합니까? –

+0

'summary = tf.identity (summary)'를 사용하지만 현재 구현과 매우 유사합니다. 나는 더 좋은 해결책을 원했지만, 그것이 내가 가진 최선이다. :) –

답변

3

나는 더 우아한 해결책이 있다고 생각하지 않는다. 설계된 행동이기 때문이다. tf.control_dependencies는 기본 그래프를 사용하여 tf.Graph.control_dependencies 호출의 바로 가기이며, 여기의 문서에서 인용입니다 :

N.B.은 제어 종속성 컨텍스트는 컨텍스트 내에서 구성된 인 작업에만 적용됩니다. 단지 컨텍스트에서 연산 또는 텐서를 사용하는 것은 제어 종속성을 추가하지 않습니다. 코멘트에 제안

# WRONG 
def my_func(pred, tensor): 
    t = tf.matmul(tensor, tensor) 
    with tf.control_dependencies([pred]): 
    # The matmul op is created outside the context, so no control 
    # dependency will be added. 
    return t 

# RIGHT 
def my_func(pred, tensor): 
    with tf.control_dependencies([pred]): 
    # The matmul op is created in the context, so a control dependency 
    # will be added. 
    return tf.matmul(tensor, tensor) 

그래서 그냥 tf.identity(summary)을 사용하여 다음 예 이 점을 보여줍니다.

관련 문제