Does the tensorflow.nn.conv1d has a gradient?

Does the tensorflow.nn.conv1d has a gradient?



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


get_gradient_function()


tensorflow.nn.conv1d


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



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


tf.get_default_graph().get_operaions()


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.


conv.op.name


conv/Squeeze


name=conv



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


op = tf.get_default_graph().get_operation_by_name('conv/Squeeze')



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)