You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to use gated pooling instead of max pooling, but i do not know how to tune the pooling gate function with the code. any help, please
`def gated_pooling(inputs, filter, size=2, learn_option='l/c'):
"""Gated pooling operation, responsive
Combine max pooling and average pooling in a mixing proportion,
which is obtained from the inner product between the gating mask and the region being
pooled and then fed through a sigmoid:
fgate(x) = sigmoid(wx) fmax(x) + (1-sigmoid(wx)) favg(x)
arguments:
inputs: input of shape [batch size, height, width, channels]
filter: filter size of the input layer, used to initialize gating mask
size: an integer, width and height of the pooling filter
learn_option: learning options of gated pooling, include:
'l/c': learn a mask per layer/channel
'l/r/c': learn a mask per layer/pooling region/channel combined
return:
outputs: tensor with the shape of [batch_size, height//size, width//size, channels]
"""
if learn_option == 'l':
gating_mask = all_channel_connected2d(inputs)
if learn_option == 'l/c':
w_gated = tf.Variable(tf.truncated_normal([size,size,filter,filter], stddev=2/(size*size*filter*2)**0.5))
gating_mask = tf.nn.conv2d(inputs, w_gated, strides=[1,size,size,1], padding='VALID')
if learn_option == 'l/r/c':
gating_mask = locally_connected2d(inputs)
alpha = tf.sigmoid(gating_mask)
x1 = tf.contrib.layers.max_pool2d(inputs=inputs, kernel_size=[size, size], stride=2, padding='VALID')
x2 = tf.contrib.layers.avg_pool2d(inputs=inputs, kernel_size=[size, size],stride=2, padding='VALID')
outputs = tf.add(tf.multiply(x1, alpha), tf.multiply(x2, (1-alpha)))
return outputs`
The text was updated successfully, but these errors were encountered:
I want to use gated pooling instead of max pooling, but i do not know how to tune the pooling gate function with the code. any help, please
`def gated_pooling(inputs, filter, size=2, learn_option='l/c'):
"""Gated pooling operation, responsive
Combine max pooling and average pooling in a mixing proportion,
which is obtained from the inner product between the gating mask and the region being
pooled and then fed through a sigmoid:
fgate(x) = sigmoid(wx) fmax(x) + (1-sigmoid(wx)) favg(x)
The text was updated successfully, but these errors were encountered: