0
让v是一个张量。如果我计算另一个张量w.r.t对v的梯度,一切正常,即Tensorflow:计算梯度w.r.t. sub-tensor
grads = tf.gradients(loss_func, v)
工作正常。
然而,当我想计算梯度WRT只是一个单一的元素或V的任何子张,我得到一个错误,即
grads = tf.gradients(loss_func, v[0,0])
grads = tf.gradients(loss_func, v[:,1:])
产生以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/henning/anaconda/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "/Users/henning/anaconda/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/Users/henning/pflow/testing.py", line 89, in <module>
theta = sess.run(grads, feed_dict={P:P_inp, Q:Q_inp})
File "/Users/henning/anaconda/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 767, in run
run_metadata_ptr)
File "/Users/henning/anaconda/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 952, in _run
fetch_handler = _FetchHandler(self._graph, fetches, feed_dict_string)
File "/Users/henning/anaconda/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 408, in __init__
self._fetch_mapper = _FetchMapper.for_fetch(fetches)
File "/Users/henning/anaconda/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 230, in for_fetch
return _ListFetchMapper(fetch)
File "/Users/henning/anaconda/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 337, in __init__
self._mappers = [_FetchMapper.for_fetch(fetch) for fetch in fetches]
File "/Users/henning/anaconda/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 337, in <listcomp>
self._mappers = [_FetchMapper.for_fetch(fetch) for fetch in fetches]
File "/Users/henning/anaconda/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 227, in for_fetch
(fetch, type(fetch)))
TypeError: Fetch argument None has invalid type <class 'NoneType'>
我究竟做错了什么?
我可以问你(与这个主题无关) - 是否w.r.t.意味着什么?因为我第n次碰到这个快捷方式,考虑了机器学习的话题,这里的人们使用它很多,所以我开始思考 – user3613919