0

I tried to use get_gradient_function() on tensorflow.nn.conv1d like this:

import tensorflow as tf
from tensorflow.python.framework.ops import get_gradient_function

d = tf.constant([1, 0, 2, 3, 0, 1, 1], dtype=tf.float32, name='d')
k = tf.constant([2, 1, 3], dtype=tf.float32, name='k')

data = tf.reshape(d, [1, int(d.shape[0]), 1], name='data')
kernel = tf.reshape(k, [int(k.shape[0]), 1, 1], name='kernel')

conv = tf.nn.conv1d(data, kernel, 1, 'SAME', name='conv')

with tf.Session() as sess:
    print (sess.run(conv))

op = tf.get_default_graph().get_operation_by_name('conv')
print(get_gradient_function(op))

I am getting the following error at the second to last line.

KeyError: "The name 'conv' refers to an Operation not in the graph."

1 Answer 1

1

It seems that there are NO 'conv' in graph, you can print all operation by tf.get_default_graph().get_operaions() shown as below

d
k
data/shape
data
kernel/shape
kernel
conv/ExpandDims/dim
conv/ExpandDims
conv/ExpandDims_1/dim
conv/ExpandDims_1
conv/Conv2D
conv/Squeeze

And conv.op.name print conv/Squeeze. so the name=conv just give outter name.

In this way, op = tf.get_default_graph().get_operation_by_name('conv/Squeeze') will work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.