2017-07-30 3 views
1
unterstützt

Hier ist die Rückverfolgung:tf.hessians() - Valueerror: Keine Werte nicht

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. 

Variablen:

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) 

Dann mit diesem Code Verfolgung funktionieren würde:

wrt_variables = [W, b] 
hess = tf.hessians(loss, wrt_variables) 

Aber das schlägt fehl:

wrt_variables = tf.concat([W, b], axis=0) 
hess = tf.hessians(loss, wrt_variables) 

Und dies würde auch scheitern:

wrt_variables = [tf.concat([W, b], axis=0)] 
hess = tf.hessians(loss, wrt_variables) 

Es schlägt fehl, auch für reshape Operationen. https://gist.github.com/guillaume-chevalier/6b01c4e43a123abf8db69fa97532993f

Danke:

Die vollständige Version dieses Codes und mit Kommentaren hier zu sehen!

Antwort

1

Dies liegt daran, dass der Knoten loss in Ihrem Diagramm nicht vom Knoten tf.concat([W,b], axis=0) abhängig ist. Es gibt keine Rückpropagation von einem auf den anderen und daher auch keine Ableitung.

Tensorflow ist keine Formal-Kalkül-Engine, es kann nur Ableitungen eines Knotens durch einen anderen Knoten schätzen, wenn ersterer hinter dem späteren liegt. So zum Beispiel auch

tf.hessian(loss, 2*W) 

wird aus den gleichen Gründen fehlschlagen (2*W ein neuer Knoten ist und loss hängt nicht davon lassen), obwohl die Beziehung zu tf.hessian(loss, W) straightfoward ist.

Beachten Sie, dass die Situatuierung mit tf.gradients identisch ist, auch wenn es anders ausfällt: Es gibt None s zurück, anstatt eine Ausnahme auszulösen.

Verwandte Themen