[英]binary threshold activation function in tensorflow
我有一段代碼使用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
你能告訴我如何用二進制步驟1替換sigmoid函數。
y = tf.round(tf.nn.sigmoid(tf.matmul(h,Wo))
這將給你0或1輸出。
在這種情況下,您不需要sigmoid。 試試relu(sign(x))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.