xmd-home

tf.session对象是执行Operation运算的一个封装环境。Tensor对象会在此执行。

比如:

 1 # Build a graph.
 2 a = tf.constant(5.0)
 3 b = tf.constant(6.0)
 4 c = a * b
 5 
 6 # Launch the graph in a session.
 7 sess = tf.compat.v1.Session()
 8 
 9 # Evaluate the tensor `c`.
10 print(sess.run(c)) # prints 30.0

 

一个Session会话在调用完成之后是需要释放的,使用close()方法来释放session。

1 # Using the `close()` method.
2 sess = tf.compat.v1.Session()
3 sess.run(...)
4 sess.close()

除此之外,也可以使用with语句来打开Session

1 with tf.compat.v1.Session() as sess:
2   sess.run(...)

 

分类:

技术点:

相关文章:

  • 2021-07-17
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
猜你喜欢
  • 2021-07-01
  • 2022-12-23
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
  • 2021-04-25
  • 2021-10-15
相关资源
相似解决方案