张量流中的二进制阈值激活函数

use*_*352 2 python tensorflow activation-function

我有一段代码使用Sigmoid激活函数进行分类,以输出[0,1]。但是我需要一个激活函数来输出0或1的二进制值。

        x = tf.placeholder("float", [None, COLUMN])
        Wh = tf.Variable(tf.random_normal([COLUMN, UNITS_OF_HIDDEN_LAYER], mean=0.0, stddev=0.05))
        h = tf.nn.sigmoid(tf.matmul(x, Wh))

        Wo = tf.Variable(tf.random_normal([UNITS_OF_HIDDEN_LAYER, COLUMN], mean=0.0, stddev=0.05))
        y = tf.nn.sigmoid(tf.matmul(h, Wo))

        # Objective functions
        y_ = tf.placeholder("float", [None, COLUMN])
        correct_prediction = tf.equal(tf.argmax(y, 1),tf.argmax(y, 1))
        cost = tf.reduce_sum(tf.cast(correct_prediction, "float"))/BATCH_SIZE
Run Code Online (Sandbox Code Playgroud)

您能告诉我如何用二进制第一步代替Sigmoid函数吗?

Rya*_*Jay 6

y = tf.round(tf.nn.sigmoid(tf.matmul(h,Wo))
Run Code Online (Sandbox Code Playgroud)

这将为您提供0或1的输出。


小智 5

在这种情况下,您不需要 sigmoid。试试 relu(sign(x))