如何在tensorflow中使用maxout激活函数?

如何在tensorflow中使用maxout激活函数?,tensorflow,Tensorflow,我想在tensorflow中使用maxout激活函数,但我不知道应该使用哪个函数。我不认为存在maxout激活,但没有任何东西可以阻止您自己进行激活。您可以执行以下操作 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))

我想在tensorflow中使用maxout激活函数,但我不知道应该使用哪个函数。

我不认为存在maxout激活,但没有任何东西可以阻止您自己进行激活。您可以执行以下操作

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)

请注意,这是我刚刚在浏览器中编写的代码,因此可能存在语法错误,但您应该了解大致情况。您只需执行一些线性变换,并在所有变换中取最大值。

我不认为存在maxout激活,但没有任何东西阻止您自己进行。您可以执行以下操作

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)

请注意,这是我刚刚在浏览器中编写的代码,因此可能存在语法错误,但您应该了解大致情况。您只需执行一些线性变换,并在所有变换中取最大值。

我发送了一个对maxout的拉取请求,以下是链接:

代码如下:

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
以下是它的工作原理:


我发送了一个对maxout的拉取请求,下面是链接:

代码如下:

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
以下是它的工作原理:

这个代码怎么样? 这似乎在我的测试中起作用

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.")
我参考了中的图表。

这段代码怎么样? 这似乎在我的测试中起作用

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.")

我参考了上1.4版的。

中的图表,您可以使用

从1.4版开始,您可以使用

Maxout是一个层,它为N*1输入计算N*M输出,然后返回整个列的最大值,即最终输出也具有N*1形状。基本上,它使用多个线性配件来模拟复杂的函数。

Maxout是一个层,它计算N*1输入的N*M输出,然后返回整个列的最大值,即最终输出的形状也是N*1。基本上,它使用多个线性配件来模拟复杂函数