计算图的使用

实战Google深度学习框架(第二版)P41

代码部分

import tensorflow as tf
a = tf.constant([1.0,2.0],name = "a")
b = tf.constant([2.0,3.0],name = "b")
result = a+b
print(a.graph is tf.get_default_graph())

g1 = tf.Graph()
with g1.as_default():
    #在计算图g1中定义变量“v”,并设置初始值0。
    v = tf.get_variable(
        "v",shape=[1],initializer=tf.ones_initializer)

遇到错误

E1129:Context manager ‘generator’ doesn’t implement enter and exit.)
TensorFlow的学习路径

查询资料

  1. 查阅相关资料:
    TensorFlow的学习路径
    来源:http://book.pythontips.com/en/latest/context_managers.html
    原文:Context Manager都是至少有一个__enter__和__exit__方法的
  2. 查询 ops.py
    TensorFlow的学习路径
    翻译:返回一个 context manager ,这个context manager 可以创建一个 图形(默认的一个图形)
    总结:可能是VSCode的default graph配置出了问题,换个编译器试试。

解决办法:换一个编译器

TensorFlow的学习路径
成功运行

相关文章:

  • 2021-08-01
  • 2021-05-26
  • 2022-01-04
  • 2021-10-09
  • 2021-11-27
  • 2021-07-07
  • 2022-02-19
猜你喜欢
  • 2021-11-10
  • 2022-01-12
  • 2021-12-14
  • 2021-07-10
  • 2021-12-03
  • 2021-12-03
  • 2021-12-06
相关资源
相似解决方案