小编Fee*_*les的帖子

TensorFlow/Python:自定义图形出现“默认堆栈违反嵌套”错误

当我尝试在自定义命名图中构造一个简单表达式时,出现了一个关于堆栈的奇怪错误。

下面的代码工作正常:

tf.reset_default_graph()

# The basic model
X = tf.placeholder(tf.float32, [None, MnistDim], "X")
W = tf.get_variable(
        name="W", 
        shape=[MnistDim, DigitCount], 
        dtype=np.float32,
        initializer=tf.zeros_initializer()
)
b = tf.get_variable(
        name="b", 
        shape=[DigitCount], 
        dtype=np.float32,
        initializer=tf.zeros_initializer()
)

a = tf.matmul(X, W, name="a") + b
y = tf.nn.softmax (a, name="y")

# The training elements  
t = tf.placeholder (tf.float32, [None, 10], "t")
cross_entropy = tf.reduce_mean(-tf.reduce_sum(t * tf.log(y), reduction_indices=[1]))
# I know about tf.nn.softmax_cross_entropy_with_logits(a)

train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
Run Code Online (Sandbox Code Playgroud)

但是,如果我通过添加以下内容将该代码放入自定义图表中:

mnist_train_graph = tf.Graph()
with mnist_train_graph.as_default():
    tf.reset_default_graph()

    # The basic model
    X = …
Run Code Online (Sandbox Code Playgroud)

python python-3.x tensorflow

0
推荐指数
1
解决办法
3340
查看次数

标签 统计

python ×1

python-3.x ×1

tensorflow ×1