除了 predict = tf.argmax(y) 之外,如何在张量流图中获得预测向量? (因为argmax仅适用于softmax分类器)
predict = tf.argmax(y)
我有一个多标签分类问题所以我需要这样的东西:
predictions = [1. if prob > 0.5 else 0. for prob in y]
希望这可以帮助 :
import tensorflow as tf import numpy as np sess = tf.InteractiveSession() prob = tf.constant(np.random.rand(10)) predictions = tf.select(prob > 0.5, tf.ones_like(prob), tf.zeros_like(prob)) print(predictions.eval())
1 回答
希望这可以帮助 :