Maxout Networks

maxout m a x o u t 的论文,参考 Goodfellow et al., 2013a
上述论文的基本翻译,参考知乎回答

本质上讲, maxout m a x o u t 的核心在于:
maxout公式
其中:
这里写图片描述
其中, j j k cursor c u r s o r i i hidden layer l a y e r cursor c u r s o r , 表示 zij z i j 由输入张量 x x 与第j W W 矩阵的第i项相称,在 k k 个相乘的结果中取最大值为隐藏层hi的值。

其他计算 hidden layer h i d d e n   l a y e r 的方法:
这里写图片描述
即直接 x x W 相乘
对上图所示的神经元的 maxout m a x o u t 的计算方法:
这里写图片描述
x x 与多个 W 相乘,取最大值得到 zij z i j
值得注意的是,此处为 Wi W i ,即为某一向量,而非需要多个 W W 矩阵

因而在实践中,常常将W 的规模乘以 k k 倍(需要手动设置), 得到k 倍的 zij z i j 后, 每 k k 个选出其中最大的,作为对应的hi的值。这一行为和max-pooling 表现一致

tensorflow t e n s o r f l o w 实现
基于 maxpooling m a x − p o o l i n g

import numpy as np
import tensorflow as tf

"""
Maxout OP from https://arxiv.org/abs/1302.4389
Max pooling is performed in given filter/channel dimension. This can also be
used after fully-connected layers to reduce number of features.
Args:
    inputs: A Tensor on which maxout will be performed
    num_units: Specifies how many features will remain after max pooling at the
      channel dimension. This must be multiple of number of channels.
    axis: The dimension where max pooling will be performed. Default is the
      last dimension.
    outputs_collections: The collections to which the outputs are added.
    scope: Optional scope for name_scope.
Returns:
    A `Tensor` representing the results of the pooling operation.
Raises:
    ValueError: if num_units is not multiple of number of features.
"""

def max_out(inputs, num_units, axis=None):
    shape = inputs.get_shape().as_list()
    if shape[0] is None:
        shape[0] = -1
    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] = num_units
    shape += [num_channels // num_units]
    outputs = tf.reduce_max(tf.reshape(inputs, shape), -1, keep_dims=False)
    return outputs

another intuitive implementation:

def maxout(x, k, m):
    d = x.get_shape().as_list()[-1]

    W = tf.Variable(tf.random_normal(shape=[d, m, k]))
    b = tf.Variable(tf.random_normal(shape = [m, k]))
    z = tf.tensordot(x, W, axes=1) + b
    z = tf.reduce_max(z, axis=2)

    return z
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值