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 Tensorflow apply_梯度抛出错误_Python_Tensorflow - Fatal编程技术网

Python Tensorflow apply_梯度抛出错误

Python Tensorflow apply_梯度抛出错误,python,tensorflow,Python,Tensorflow,我得到一个错误: TypeError:“AssignAdd”Op的输入“ref”需要l值输入 在下面函数的train行apply_gradient\u op=opt.apply_gradients(梯度,全局_step=stepNum) def x1_x2_diff_net_v0(): x = tf.placeholder(tf.float32, [None, 4]) lb = tf.placeholder(tf.float32, [None, 2]) #First fc laye

我得到一个错误:

TypeError:“AssignAdd”Op的输入“ref”需要l值输入

在下面函数的
train
apply_gradient\u op=opt.apply_gradients(梯度,全局_step=stepNum)

def x1_x2_diff_net_v0():
  x  = tf.placeholder(tf.float32, [None, 4])
  lb = tf.placeholder(tf.float32, [None, 2])
  #First fc layer
  with tf.variable_scope('fc1') as scope:
    w = tfu.get_weights([4,100], name='fc1_w')
    b = tfu.get_bias([1,100], name='fc1_b')
  fc1 = tf.nn.relu(tf.matmul(x, w) + b)
  #Prediction layer
  with tf.variable_scope('pred') as scope:
    w = tfu.get_weights([100,2], name='pred_w')
    b = tfu.get_bias([1, 2], name='pred_b')
  pred = tf.nn.relu(tf.matmul(fc1, w) + b)
  #Define the loss
  loss = tf.nn.l2_loss(pred - lb, name='loss')
  return loss

def train(stepNum, initLr=0.01):
  g = tf.Graph()
  with g.as_default():
    loss    = x1_x2_diff_net_v0()
    lr = tf.train.exponential_decay(initLr, stepNum, 100,
                 0.1, staircase=True)
    for tv in tf.trainable_variables():
      print (tv.name)
    # Compute gradients.
    opt = tf.train.GradientDescentOptimizer(lr)
    grads = opt.compute_gradients(loss)
    # Apply gradients.
    apply_gradient_op = opt.apply_gradients(grads, global_step=stepNum)

有没有关于什么地方出了问题的建议?我从
cifar10.py
示例文件中的te方法
train
中提取代码片段

哎呀!我将一个整数传递到stepNum而不是tf.Variable。现在问题解决了。如果错误信息更加直观,那就太好了

哎呀!我将一个整数传递到stepNum而不是tf.Variable。现在问题解决了。如果错误信息更加直观,那就太好了