Error de ejemplo oficial de gradiente ZeroOut: AttributeError: el objeto 'list' no tiene el atributo 'eval'
Seguí el tutorial oficial del sitio web de tensorflow:https: //www.tensorflow.org/extend/adding_an_o También se describe cómo llamar al gradiente del ejemplo ZeroOut en el tutorial que quiero probar en este breve fragmento de código debajo.
He encontrado el código aquí:https: //github.com/MatteoRagni/tf.ZeroOut.gp
import numpy as np
import tensorflow as tf
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import sparse_ops
zero_out_module = tf.load_op_library('./libzeroout.so')
@ops.RegisterGradient("ZeroOut")
def _zero_out_grad(op, grad):
to_zero = op.inputs[0]
shape = array_ops.shape(to_zero)
index = array_ops.zeros_like(shape)
first_grad = array_ops.reshape(grad, [-1])[0]
to_zero_grad = sparse_ops.sparse_to_dense([index], shape, first_grad, 0)
return [to_zero_grad] # List of one Tensor, since we have one input
t_in = tf.placeholder(tf.int32, [None,None])
ret = zero_out_module.zero_out(t_in)
grad = tf.gradients(ys=tf.reduce_sum(ret), xs=t_in)
with tf.Session(''):
feed_dict = {t_in: [[1, 2], [3, 4]]}
print "ret val: ", ret.eval(feed_dict=feed_dict)
print "grad: ", grad
print "grad: ", grad.eval(feed_dict=feed_dict)
Recibí este error ...
AttributeError: 'list' object has no attribute 'eval'
... pero puedo hacer ret.eval ().
¿Por qué no puedo llamar a grad.eval ()? Quiero ver estos valores dentro del tensor de graduación. ¿Cómo depurar gradiente?