ValueError: An operation has None for gradient
错误表现
在使用自定义的层模型搭建完毕之后, 运行fit
进行训练时, 报如下的错误:
ValueError: An operation has `None` for gradient. Please make sure that all of your ops have a gradient defined (i.e. are differentiable). Common ops without gradient: K.argmax, K.round, K.eval.
错误原因
在自定义层中的build
方法里, 定义了一些变量, 但是如果有变量在call
方法中没有被使用, 就会报上面的错误.
解决方法
检查自定义层的定义.
参考资料
最后更新于
这有帮助吗?