【问题标题】:how to fix tf.constant unexpected argument error如何修复 tf.constant 意外参数错误
【发布时间】:2019-01-22 16:20:17
【问题描述】:

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

原来FLAGS = tf.app.flags.FLAGS,同样改为tf.flags.FLAGS。

但是 tf.constant 中的错误在这两种情况下都存在。如何解决? 我觉得这个错误与python版本有关。但想不通

replica_id=tf.constant(FLAGS.task, dtype=tf.int32, shape=()),

【问题讨论】:

    标签: tensorflow resnet


    【解决方案1】:

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

    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 不适用于我的。我想也许错误不是来自那个函数。它在另一个函数中使用。
    • 优化器 = tf.train.SyncReplicasOptimizer( opt=优化器,replicas_to_aggregate=FLAGS.replicas_to_aggregate,variable_averages=variable_averages,variables_to_average=moving_average_variables,replica_id=tf.constant(value=FLAGS.task,dtype=tf. int32), total_num_replicas=FLAGS.worker_replicas)
    • 您能否再分享几行代码以更好地理解工作流程?
    • 您使用的是哪个 Tensorflow 版本?因为在 1.12.0 中 tf.train.SyncReplicasOptimizer() 没有定义 replica_id 参数
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-06
    • 2015-04-24
    • 2022-06-10
    • 2015-02-09
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多