TensorFlow的学习路径

TensorFlow的学习路径

  • 计算图的使用
    • 实战Google深度学习框架(第二版)P41
      • 代码部分
      • 遇到错误
      • 查询资料
      • 解决办法:换一个编译器

计算图的使用

实战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张图片

查询资料

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

解决办法:换一个编译器

TensorFlow的学习路径_第4张图片
成功运行

你可能感兴趣的:(TensorFlow)