解决TensorFlow中‘SGD‘ object has no attribute ‘apply_gradient’报错问题

昨天使用TensorFlow训练时出现了’SGD’ object has no attribute ‘apply_gradient’的问题,注意不是apply_gradients
解决TensorFlow中‘SGD‘ object has no attribute ‘apply_gradient’报错问题

于是查了下解决办法,发现没有特别有用的,不是copy别人的就是说增加
from tensorflow_core.python.keras import datasets, layers,于是决定自己排除原因。
首先查看keras的安装目录:
解决TensorFlow中‘SGD‘ object has no attribute ‘apply_gradient’报错问题
进入keras的目录,然后发现有解决TensorFlow中‘SGD‘ object has no attribute ‘apply_gradient’报错问题

于是打开optimizers.py文件,发现没有apply_gradient,,而是变为了apply_gradients。因此代码里面的apply_gradient改为apply_gradients即可。
解决TensorFlow中‘SGD‘ object has no attribute ‘apply_gradient’报错问题