Working with multiple graphs in TensorFlow

前端 未结 6 717
一个人的身影
一个人的身影 2020-11-27 15:28

Can someone explain to me how name_scope works in TensorFlow?

Suppose I have the following code:



        
6条回答
  •  Happy的楠姐
    2020-11-27 15:49

    Your product is a global variable, and you've set it to point to "g2/MatMul".

    In particular

    Try

    print product
    

    and you'll see

    Tensor("g2/MatMul:0", shape=(1, 1), dtype=float32)
    

    So the system takes "g2/MatMul:0" since that's the Tensor's name, and tries to find it in the graph g1 since that's the graph you set for the session. Incidentally you can see all nodes in the graph print [n.name for n in g1.as_graph_def().node]

    Generally, using more than one graph is rarely useful. You can't merge them and can't pass tensors between them. I'd recommend just doing

    tf.reset_default_graph()
    a = tf.Constant(2)
    sess = tf.InteractiveSession()
    ....
    

    This way you'll have one default graph and one default session and you can omit specifying graph or session in most cases. If you ever need to refer to them explicitly, you can get them from tf.get_default_graph() or tf.get_default_session()

提交回复
热议问题