1
這裏是回溯:tf.hessians() - ValueError異常:無值不支持
Traceback (most recent call last):
File "test.py", line 39, in <module>
hess = tf.hessians(loss, wrt_variables)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/ops/gradients_impl.py", line 970, in hessians
_gradients = array_ops.unstack(_gradients)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/ops/array_ops.py", line 952, in unstack
value = ops.convert_to_tensor(value)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/ops.py", line 639, in convert_to_tensor
as_ref=False)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/ops.py", line 704, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/constant_op.py", line 113, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/constant_op.py", line 102, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/framework/tensor_util.py", line 360, in make_tensor_proto
raise ValueError("None values not supported.")
ValueError: None values not supported.
變量:
import tensorflow as tf
data_x = [0., 1., 2.]
data_y = [-1., 1., 3.]
batch_size = len(data_x)
x = tf.placeholder(shape=[batch_size], dtype=tf.float32, name="x")
y = tf.placeholder(shape=[batch_size], dtype=tf.float32, name="y")
W = tf.Variable(tf.ones(shape=[1]), dtype=tf.float32, name="W")
b = tf.Variable(tf.zeros(shape=[1]), dtype=tf.float32, name="b")
pred = x * W + b
loss = tf.reduce_mean(0.5 * (y - pred)**2)
然後,跟隨了這個代碼將工作:
wrt_variables = [W, b]
hess = tf.hessians(loss, wrt_variables)
但是這個失敗:
wrt_variables = tf.concat([W, b], axis=0)
hess = tf.hessians(loss, wrt_variables)
,這也將失敗:
wrt_variables = [tf.concat([W, b], axis=0)]
hess = tf.hessians(loss, wrt_variables)
它也沒有爲重塑業務。
的這個代碼,並帶有註釋的完整版本可以在這裏看到: https://gist.github.com/guillaume-chevalier/6b01c4e43a123abf8db69fa97532993f
謝謝!