tensorflow argmax返回元组?

时间:2017-11-13 09:58:30

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

我试图用tf.contrib.estimator构建张量流中的神经网络 但

 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>,)

1 个答案:

答案 0 :(得分:0)

问题出在结尾处的逗号

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