apf*_*alz 5 gradient tensorflow
我正在尝试调整tf DeepDream教程代码以使用其他模型.现在我打电话给tf.gradients()时:
t_grad = tf.gradients(t_score, t_input)[0]
g = sess.run(t_grad, {t_input:img0})
Run Code Online (Sandbox Code Playgroud)
我收到类型错误:
TypeError: Fetch argument None of None has invalid type <type 'NoneType'>,
must be a string or Tensor. (Can not convert a NoneType into a Tensor or
Operation.)
Run Code Online (Sandbox Code Playgroud)
我应该在哪里开始寻找修复此错误?
是否可以将tf.gradients()与其中包含Optimizer的模型一起使用?
我猜你t_grad
有一些None
.None
在数学上等价于0渐变,但是当成本不依赖于它被区分的参数时,返回特殊情况.我们不仅仅返回0而不是None
您在此处讨论中可以看到的原因有很多种
因为None
在上面的情况下或者在计算二阶导数时可能很烦人,我使用下面的辅助函数
def replace_none_with_zero(l):
return [0 if i==None else i for i in l]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4198 次 |
最近记录: |