TypeError: __init__() got an unexpected keyword argument 'shape'
程序员文章站
2022-06-13 10:03:14
...
tensorFlow入门书籍中的代码
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("v2", initializer=tf.ones_initializer(shape=[3,2])())
with tf.Session(graph=g1) as sess:
tf.global_variables_initializer().run()
with tf.variable_scope("", reuse=True):
print(sess.run(tf.get_variable("v")))
with tf.Session(graph=g2) as sess:
tf.global_variables_initializer().run()
with tf.variable_scope("", reuse=True):
print(sess.run(tf.get_variable("v2")))
运行的时候遇到如下问题
Traceback (most recent call last):
File "C:/Users/Tobin/PycharmProjects/TF_study/test1.py", line 5, in <module>
v = tf.get_variable("v", initializer=tf.zeros_initializer(shape=[1]))
TypeError: __init__() got an unexpected keyword argument 'shape
网上搜了下发现,最新版的TensorFlow已经不支持这样的写法了,应该讲代码改成
v = tf.get_variable("v2", initializer=tf.ones_initializer()(shape=[3,2]))
那本《TensorFlow:实战Google深度学习框架》是比较早的一本书了,里面部分函数的的用法可能现在已经不支持了,所以要注意下
上一篇: [集成框架]基于VueCli3的微信公众号项目前端框架
下一篇: js 兼容浏览器
推荐阅读
-
报错解决Python Error fix-TypeError: _mean() got an unexpected keyword argument ‘dim‘
-
login() got an unexpected keyword argument 'extra_context'
-
TypeError: softmax() got an unexpected keyword argument 'axis' 解决办法
-
Django报错:TypeError: render() got an unexpected keyword argument 'renderer'
-
TypeError: login() got an unexpected keyword argument 'template_name'
-
TypeError: filter() got an unexpected keyword argument
-
解决 报错 TypeError: interleave() got an unexpected keyword argument ‘deterministic‘
-
TypeError: __init__() got an unexpected keyword argument 'shape'
-
Django TypeError: render() got an unexpected keyword argument 'renderer'
-
TypeError: got an unexpected keyword argument ‘id‘