学习TensorFlow遇到的问题:

1 如何在不同计算图上定义和使用变量

书上代码:

import tensorflow as tfg1 = tf.Graph()
with g1.as_default():#在计算g1中定义变量“v”,并设置初始值为0。v = tf.get_variable("v", initializer=tf.zeros_initializer(shape=[1]))
g2 = tf.Graph()
with g2.as_default():#在计算图g2中定义变量"v",并设置初始值为1.v=tf.get_variable("v", initializer=tf.ones_initializer(shape=[1]))#在计算图g1中读取变量“v”的取值。
with tf.Session(graph=g1) as sess:#tf.initialize_all_variables().runtf.global_variables_initializer().run()with tf.variable_scope("",reuse=True):#在计算图g1中,变量“v”的取值应该为0,所以下面这行会输出[0.]print(sess.run(tf.get_variable("v")))#在计算图g2中读取变量”v“的取值
with tf.Session(graph=g2) as sess:tf.initialize_all_variables().run()with tf.variable_scope("",reuse=True):#在计算图g2中,变量”v“的取值应该为1,所以下面这行会输出[1.]print(sess.run(tf.get_variable("v")))

报错:

故在网上找了原因:

参考博客https://blog.csdn.net/MissXy_/article/details/78597498

了解到是由于python版本的问题

错误更改:

v = tf.get_variable("v", shape=[1], initializer=tf.zeros_initializer)

虽然输出了结果但是会有警告如下图:

警告更改:

tf.global_variables_initializer().run()

参照 博客下面的评论了解到是由于新版tf.zeros_initializer和ones_initializer后面需要加括号

tf.get_variable(“v”,initializer=tf.zeros_initializer(shape=[1]))

改为:

v = tf.get_variable(“v”,initializer=tf.zeros_initializer( )(shape=[1]))

python中错误TypeError: __init__() got an unexpected keyword argument 'shape'相关推荐

  1. 【Python异常】TypeError: __init__() got an unexpected keyword argument ‘size‘与gensim.models.word2vec 参数

    文章目录 一.遇到的异常: 1.TypeError: __init__() got an unexpected keyword argument 'size' 2.TypeError: __init_ ...

  2. TensorFlow错误:TypeError: __init__() got an unexpected keyword argument 'serialized_options'

    用了好久的时间搞定了机器学习,今天想搞一搞深度学习,用TensorFlow的过程中却遇到了错误: Traceback (most recent call last):File "F:/编程/ ...

  3. json.loads时TypeError: __init__() got an unexpected keyword argument ‘encoding‘ 的解决方案

      大家好,我是爱编程的喵喵.双985硕士毕业,现担任全栈工程师一职,热衷于将数据思维应用到工作与生活中.从事机器学习以及相关的前后端开发工作.曾在阿里云.科大讯飞.CCF等比赛获得多次Top名次.现 ...

  4. 成功解决TypeError: __init__() got an unexpected keyword argument 'serialized_options'

    成功解决TypeError: __init__() got an unexpected keyword argument 'serialized_options' 目录 解决问题 解决思路 解决方法 ...

  5. TypeError: __init__() got an unexpected keyword argument #34serialized_options #34

    TypeError: __init__() got an unexpected keyword argument 'serialized_options' TypeError: __init__() ...

  6. 成功解决TypeError: __init__() got an unexpected keyword argument 'indices'

    成功解决TypeError: __init__() got an unexpected keyword argument 'indices' 目录 解决问题 解决思路 解决方法 解决问题 TypeEr ...

  7. 成功解决TypeError: __init__() got an unexpected keyword argument 'n_iterations'

    成功解决TypeError: __init__() got an unexpected keyword argument 'n_iterations' 目录 解决问题 解决思路 解决方法 解决问题 T ...

  8. Jupyter notebook: TypeError: __init__() got an unexpected keyword argument 'io_loop 问题

    使用环境:Anaconda3(Python3.6) 创建一个新的notebook时,无法连接到kernel,terminal上显示错误为:TypeError: __init__() got an un ...

  9. TypeError: __init__() got an unexpected keyword argument ‘任意数‘的原因及解决办法

    本篇文章主要讲解 pymysql模块查询数据时报错 "TypeError: init() got an unexpected keyword argument '任意数'的原因及解决办法&q ...

最新文章

  1. topcoder srm 711 div1 -3
  2. 「新房+电商+大数据」如何塑造满意度达 99.8% 的万亿市场领路人?
  3. 细数开源历史上的九个重大事件
  4. java 内部类序列化_Gson如何序列化内部类
  5. RobotStudio双传送带系统的搭建
  6. Android 布局渲染流程与卡顿优化
  7. springboot日志框架
  8. redis java 存储对象_安装redis 并把java对象存放在redis中
  9. 步进电机原理及参数详解
  10. 更改桌面 计算机 的图标w10,W10电脑系统如何修改桌面快捷方图标
  11. shader篇-立方体纹理
  12. 流利阅读 2019.1.22 Theresa May loses big over her Brexit deal
  13. 一种通过物理分离实现WSUS伸缩性的方案
  14. html字母上方加箭头,html5怎么在图片上加左右箭头
  15. ML-Agents学习之RollerBall项目
  16. Python的字符串比较
  17. 给大家介绍下,这是我的流程图软件 —— draw.io
  18. 软件测试定义/过程/分类
  19. Linux进阶(3)--RAID简介
  20. 新手BIOS放电主要事项

热门文章

  1. 认真CS☀️增量时间—Time.deltaTime Time.fixedDeltaTime
  2. 回忆过往,坚守初心 —— 从头记过往的搞机时光
  3. 【华为诺亚方舟实验室】招聘:决策推理(强化学习)研究方向(实习、应届、社招、博后)均可以
  4. JavaScript实现大图展示(放大镜)
  5. 基于神经网络rnn模型心脏病特征预测心脏病
  6. Python爬虫:爬取链接被加密的网站中的视频《传闻中的陈芊芊》
  7. CS230 Full-cycle DL progjects
  8. 程序员工作经验谈之商贸平台
  9. 灰色关联分析(GRA)的理论及应用(matlab和python)
  10. python(分割txt为多个txt)