【问题标题】:binary threshold activation function in tensorflow张量流中的二进制阈值激活函数
【发布时间】:2018-03-04 15:15:20
【问题描述】:

我有一段代码使用 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

你能告诉我如何用二进制第一步替换 sigmoid 函数吗?

【问题讨论】:

    标签: python tensorflow activation-function


    【解决方案1】:
    y = tf.round(tf.nn.sigmoid(tf.matmul(h,Wo))
    

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-12
      • 2018-11-01
      • 2021-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-02
      • 2018-05-28
      相关资源
      最近更新 更多