2016-10-10 41 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的图。

相关问题