Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 梯度张量流返回无_Python_Tensorflow - Fatal编程技术网

Python 梯度张量流返回无

Python 梯度张量流返回无,python,tensorflow,Python,Tensorflow,为了实现一个优化器,我必须计算两次梯度,但是第二个梯度(g_n)没有返回任何值 for i in range(1): with tf.GradientTape(persistent= True) as tape: ypredicted = linear_model(Xtrain) l = squared_loss(ytrain, ypredicted) g = tape.gradient(l, w) radius = 1 sigma = np.float64(np.random

为了实现一个优化器,我必须计算两次梯度,但是第二个梯度(g_n)没有返回任何值

for i in range(1):

with tf.GradientTape(persistent= True) as tape:
  ypredicted = linear_model(Xtrain)
  l = squared_loss(ytrain, ypredicted)


g = tape.gradient(l, w) 

radius = 1
sigma = np.float64(np.random.randn())
RS = tf.fill((number_feature,1), radius*sigma)


W_N = tf.math.add(w, RS)
S = tf.math.subtract (w, W_N)  

g_n = tape.gradient(l, tf.Variable(W_N, trainable = True))