TypeError: __init__() got an unexpected keyword argument 'shape'
2017-11-08 09:22
851 查看
采用TensorFlow支持通过tf.Graph函数来生成新的向量图,代码如下:
执行后发生如下错误:
解决办法:因为上述代码写法是TensorFlow旧版本的写法,将Line6 和Line10 改如下如下可以实现代码的正常运行:
v = tf.get_variable("v",initializer=tf.zeros_initializer()(shape = [1]))
v = tf.get_variable( "v",initializer=tf.ones_initializer()(shape = [1]))
输出结果如下图:
明显有一个更新提示,表示该初始化的语句也需要进行更新:
tf.initialize_all_variables().run() 变成 tf.global_variables_initializer().run()
最后输出结果:
参考链接:https://stackoverflow.com/questions/44946189/typeerror-init-got-an-unexpected-keyword-argument-shape
import tensorflow as tf g1 = tf.Graph() with g1.as_default(): v = tf.get_variable( "v",initializer=tf.zeros_initializer(shape = [1])) g2 = tf.Graph() with g2.as_default(): v = tf.get_variable( "v",initializer=tf.ones_initializer(shape = [1])) with tf.Session(graph=g1) as sess: tf.initialize_all_variables().run() with tf.variable_scope("",reuse=True): print(sess.run(tf.get_variable("v"))) with tf.Session(graph=g2) as sess: tf.initialize_all_variables().run() with tf.variable_scope("",reuse=True): print(sess.run(tf.get_variable("v")))
执行后发生如下错误:
解决办法:因为上述代码写法是TensorFlow旧版本的写法,将Line6 和Line10 改如下如下可以实现代码的正常运行:
v = tf.get_variable("v",initializer=tf.zeros_initializer()(shape = [1]))
v = tf.get_variable( "v",initializer=tf.ones_initializer()(shape = [1]))
输出结果如下图:
明显有一个更新提示,表示该初始化的语句也需要进行更新:
tf.initialize_all_variables().run() 变成 tf.global_variables_initializer().run()
最后输出结果:
参考链接:https://stackoverflow.com/questions/44946189/typeerror-init-got-an-unexpected-keyword-argument-shape
相关文章推荐
- TypeError: __init__() got an unexpected keyword argument 'shape'
- TypeError: __init__() got an unexpected keyword argument ‘maxlength’
- RESTful学习笔记 --- TypeError: __init__() got an unexpected keyword argument 'method'
- Python openpyxl TypeError: __init__() got an unexpected keyword argument 'pivotButton' (and)
- TypeError: __init__() got an unexpected keyword argument ‘maxlength’
- tensorflow 1.5 TypeError: __init__() got an unexpected keyword argument 'dct_method'
- TypeError: __init__() got an unexpected keyword argument 'syntax'
- TypeError:__init__() got an unexpected keyword argument 'xxx'
- 《Flask Web开发》学习笔记之bug--(6)【TypeError: __init__() got an unexpected keyword argument 'method'】
- TypeError: __init__() got an unexpected keyword argument ‘maxlength’
- TypeError: __init__() got an unexpected keyword argument ‘default’
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- Keras TypeError: run() got an unexpected keyword argument 'class_mode'
- Keras TypeError: run() got an unexpected keyword argument 'class_mode'
- 报错TypeError: pool_2d() got an unexpected keyword argument 'ws'
- python pandas 报错:TypeError: parser_f() got an unexpected keyword argument 'skip_blank_lines'
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- 【Python配置】TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- TypeError: linspace() got an unexpected keyword argument 'dtype'