NameError: name 'sess' is not defined

Lig*_*ght 3 python-3.x tensorflow

I am running python program under tensorflow. When I input sess.run(),the command line prompt me that NameError: name 'sess' is not defined

print(sess.run(W_conv1))
Traceback (most recent call last):

  File "<ipython-input-17-cf7d3892efbb>", line 1, in <module>
    print(sess.run(W_conv1))

NameError: name 'sess' is not defined
Run Code Online (Sandbox Code Playgroud)

Alb*_*295 5

你必须定义sess. 在访问它之前放置此行。

sess = tf.Session()

甚至你可以使用一个with语句:

with tf.Session() as sess:

    #Do something with sess
    print(sess.run(W_conv1))
Run Code Online (Sandbox Code Playgroud)