Tensorflow 如何修复tf.constant意外参数错误

Tensorflow 如何修复tf.constant意外参数错误,tensorflow,resnet,Tensorflow,Resnet,在原始代码中,标志设置为tf.apps.flags.DEFINE_string “主机”,“要使用的TensorFlow主机的地址。”。然后我将tf.app.flags更改为tf.flags 最初FLAGS=tf.app.FLAGS.FLAGS,类似地更改为tf.FLAGS.FLAGS 但在这两种情况下,tf.constant中的错误都存在。如何修复它? 我觉得这个错误与python版本有关。但是我想不出来 replica_id=tf.constantFLAGS.task,dtype=tf.in

在原始代码中,标志设置为tf.apps.flags.DEFINE_string “主机”,“要使用的TensorFlow主机的地址。”。然后我将tf.app.flags更改为tf.flags

最初FLAGS=tf.app.FLAGS.FLAGS,类似地更改为tf.FLAGS.FLAGS

但在这两种情况下,tf.constant中的错误都存在。如何修复它? 我觉得这个错误与python版本有关。但是我想不出来


replica_id=tf.constantFLAGS.task,dtype=tf.int32,shape=,

试试这个,对我来说效果很好:

import tensorflow as tf

FLAGS = tf.flags.FLAGS
tf.flags.DEFINE_integer('task', 10, "my value for the constant")

# now define your constant
replica_id = tf.constant(value=FLAGS.task, dtype=tf.float32)

# see if it works:
with tf.Session() as sess:
  print(sess.run(replica_id))

谢谢你的回答。当我自己运行代码时,您的代码在我的代码上运行。但是更改为value=FLAGS.task对我的不起作用。我想这个错误可能不是来自这个函数。它在另一个函数中使用。optimizer=tf.train.syncReplicateSOptimizer opt=optimizer,replica\u to\u aggregate=FLAGS.replica\u to\u aggregate,variable\u averages=variable\u averages=variable\u averages,variables\u to\u average=movings\u average\u averages,replica\u id=tf.constantvalue=FLAGS.tas,total_num_replicas=FLAGS.worker\u replica请共享另外几行代码以更好地理解工作流?您使用的是哪个Tensorflow版本?因为在1.12.0中,tf.train.SyncReplicasOptimizer没有定义副本id参数