tensorflow argmax returns 元组?
tensorflow argmax returns tuple?
我正在尝试使用 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))
returns 一个错误:
raise TypeError('{} must be Tensor, given: {}'.format(tensor_name, x)) TypeError: predictions must be Tensor, given: (<tf.Tensor 'ArgMax:0' shape=(10,) dtype=int64>,)
问题出在结尾处的逗号中
y = tf.argmax(logits, axis=1),
我正在尝试使用 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))
returns 一个错误:
raise TypeError('{} must be Tensor, given: {}'.format(tensor_name, x)) TypeError: predictions must be Tensor, given: (<tf.Tensor 'ArgMax:0' shape=(10,) dtype=int64>,)
问题出在结尾处的逗号中
y = tf.argmax(logits, axis=1),