2016-10-10 37 views

回答

1

我不認爲有一個最大激活,但沒有什麼能阻止你自己做出來。你可以做如下的事情。

with tf.variable_scope('maxout'): 
    layer_input = ... 
    layer_output = None 
    for i in range(n_maxouts): 
    W = tf.get_variable('W_%d' % d, (n_input, n_output)) 
    b = tf.get_variable('b_%d' % i, (n_output,)) 
    y = tf.matmul(layer_input, W) + b 
    if layer_output is None: 
     layer_output = y 
    else: 
     layer_output = tf.maximum(layer_output, y) 

注意,這是代碼,我只是在我的瀏覽器中寫道所以有可能是語法錯誤,但你應該得到的總體思路。您只需執行許多線性變換,並在所有變換中取得最大值。

4

我找來MAXOUT拉入請求,這裏是鏈接:

https://github.com/tensorflow/tensorflow/pull/5528

代碼如下:

def maxout(inputs, num_units, axis=None): 
    shape = inputs.get_shape().as_list() 
    if axis is None: 
     # Assume that channel is the last dimension 
     axis = -1 
    num_channels = shape[axis] 
    if num_channels % num_units: 
     raise ValueError('number of features({}) is not a multiple of num_units({})' 
      .format(num_channels, num_units)) 
    shape[axis] = -1 
    shape += [num_channels // num_units] 
    outputs = tf.reduce_max(tf.reshape(inputs, shape), -1, keep_dims=False) 
    return outputs 

這裏是它如何工作的:

github screenshot

0

這段代碼如何? 這似乎在我的測試中工作。

def max_out(input_tensor,output_size): 
shape = input_tensor.get_shape().as_list() 
if shape[1] % output_size == 0: 
    return tf.transpose(tf.reduce_max(tf.split(input_tensor,output_size,1),axis=2)) 
else: 
    raise ValueError("Output size or input tensor size is not fine. Please check it. Reminder need be zero.") 

我指在the following page的圖。

相關問題