在学习莫烦python中tensorflow教程中遇到
loss
passed to Optimizer.compute_gradients should be a function when eager execution is enabl
以及根据网上修改后出现
No variables to optimize等错误代码
出现问题的原因呢就是因为tensorflow1.x版本和2.x版本问题,不要以为将指令改为2.X版本的就万事大吉了,根出问题了.
为了方便对比理解,附上大佬源代码
并用相同数据和先同思路及算法,附上我写的2.3版本
下面是莫烦大佬源代码
from __future__ import print_function
import tensorflow as tf
import numpy as np
# create data
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data*0.1 + 0.3
### create tensorflow structure start ###
Weights = tf.Variable(tf.random_uniform([1], -1.0, 1.0