我已经尝试了tensorflow==0.12.1
,我遇到了以下问题:
我正在尝试运行:
inp = tf.placeholder(tf.float32, [None, 10, 10, 3], name='inp')
var = tf.nn.batch_normalization(inp, mean, variance, offset, scale, variance_epsilon)
training = tf.placeholder(tf.bool, name='training')
x1 = np.random.random([20, 10, 10, 3])
config = tf.ConfigProto(device_count={'GPU': 0})
with tf.Session(config=config) as sess:
sess.run(tf.global_variables_initializer())
result = var.eval({inp: x1, training: True}, sess)
但我正在追踪堆栈跟踪:
文件“myscript.py”,第35行,在tf_run中 sess.run(tf.global_variables_initializer()) 文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py”, 第766行,在运行中 run_metadata_ptr) 文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py”, 第964行,在_run feed_dict_string,options,run_metadata) 文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py”, 第1014行,在_do_run中 target_list,options,run_metadata) 文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py”, 第1034行,在_do_call中 提升类型(e)(node_def,op,message) InvalidArgumentError:您必须使用dtype bool [[Node:training =]为占位符张量'training'提供一个值 Placeholderdtype = DT_BOOL,shape = [], _device = “/作业:本地主机/复制:0 /任务:0 / CPU:0”]]
Caused by op u'training', defined at: File "myscript.py", line 30, in tf_run training = tf.placeholder(tf.bool, name='training') File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py",
第1587行,占位符 名称=名称) 文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py”, 第2043行,在_placeholder中 名称=名称) 文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py”, 第759行,在apply_op中 op_def = op_def) 文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py”, 第2240行,在create_op中 original_op = self._default_original_op,op_def = op_def) 文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py”, 第1128行,在 init 中 self._traceback = _extract_stack()
此问题出现在:
Ubuntu 16.04.1 - tensorflow GPU
安装
仅Mac - tensorflow CPU
安装
当我尝试降级到tensorflow==0.11.0
并替换行
sess.run(tf.global_variables_initializer()
通过
sess.run(tf.initialize_all_variables())
,然后一切正常。
tensorflow repo中的相关问题是https://github.com/tensorflow/tensorflow/issues/6661