小编Qwe*_*rtz的帖子

在TensorFlow中使用多个图形

有人可以向我解释name_scopeTensorFlow中的工作原理吗?

假设我有以下代码:

import tensorflow as tf

g1 = tf.Graph()
with g1.as_default() as g:
    with g.name_scope( "g1" ) as scope:
        matrix1 = tf.constant([[3., 3.]])
        matrix2 = tf.constant([[2.],[2.]])
        product = tf.matmul(matrix1, matrix2)

tf.reset_default_graph()

g2 = tf.Graph()
with g2.as_default() as g:
    with g.name_scope( "g2" ) as scope:
        matrix1 = tf.constant([[4., 4.]])
        matrix2 = tf.constant([[5.],[5.]])
        product = tf.matmul(matrix1, matrix2)

tf.reset_default_graph()

with tf.Session( graph = g1 ) as sess:
    result = sess.run( product )
    print( result )
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我收到以下错误消息:

Tensor Tensor("g2/MatMul:0", shape=(1, 1), dtype=float32) …
Run Code Online (Sandbox Code Playgroud)

tensorflow

30
推荐指数
2
解决办法
3万
查看次数

标签 统计

tensorflow ×1