【问题标题】:tensorflow argmax returns tuple?tensorflow argmax 返回元组?
【发布时间】:2017-11-13 09:58:29
【问题描述】:

我正在尝试使用 tf.contrib.estimator 在 tensorflow 中构建神经网络 但是

 logits = tf.reduce_mean(conv2, axis=[1, 2])

    y = tf.argmax(logits, axis=1),
    # If prediction mode, early return
    if mode == tf.estimator.ModeKeys.PREDICT:
        return tf.estimator.EstimatorSpec(mode, predictions=y)

    loss_op = tf.losses.softmax_cross_entropy(onehot_labels=y_onehot, logits=logits)
    optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
    train_op = optimizer.minimize(loss_op, global_step=tf.train.get_global_step())

    # Add evaluation metrics (for EVAL mode)
    acc_op = tf.contrib.metrics.accuracy(labels=y_, predictions=tf.cast(y, tf.uint8))

返回错误:

 raise TypeError('{} must be Tensor, given: {}'.format(tensor_name, x)) TypeError: predictions must be Tensor, given: (<tf.Tensor  'ArgMax:0' shape=(10,) dtype=int64>,)

【问题讨论】:

  • conv2 的形状是什么?
  • argmax 之后你期望得到什么?
  • conv2 形状为 (10, 360, 640, 2)
  • @Sunreef ,在 argmax 之后,我希望张量的形状为 (10,) 而不是它的元组

标签: python python-3.x tensorflow neural-network tensorflow-serving


【解决方案1】:

问题以逗号结尾

y = tf.argmax(logits, axis=1),

【讨论】:

    猜你喜欢
    • 2019-09-26
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    相关资源
    最近更新 更多