Пример #1
0
 def add_forward(self, data: sym.Variable):
     """Add neural network model."""
     conv1 = sym.Convolution(
         data, name='conv1', num_filter=64, kernel=(3, 3), stride=(2, 2))
     relu1 = sym.Activation(conv1, act_type='relu')
     pool1 = sym.Pooling(relu1, pool_type='max', kernel=(3, 3), stride=(2, 2))
     fire2 = self._fire_layer('fire2', pool1, s1x1=16, e1x1=64, e3x3=64)
     fire3 = self._fire_layer('fire3', fire2, s1x1=16, e1x1=64, e3x3=64)
     pool3 = sym.Pooling(fire3, name='pool3', kernel=(3, 3), stride=(2, 2), pool_type='max')
     fire4 = self._fire_layer('fire4', pool3, s1x1=32, e1x1=128, e3x3=128)
     fire5 = self._fire_layer('fire5', fire4, s1x1=32, e1x1=128, e3x3=128)
     pool5 = sym.Pooling(fire5, name='pool5', kernel=(3, 3), stride=(2, 2), pool_type='max')
     fire6 = self._fire_layer('fire6', pool5, s1x1=48, e1x1=192, e3x3=192)
     fire7 = self._fire_layer('fire7', fire6, s1x1=48, e1x1=192, e3x3=192)
     fire8 = self._fire_layer('fire8', fire7, s1x1=64, e1x1=256, e3x3=256)
     fire9 = self._fire_layer('fire9', fire8, s1x1=64, e1x1=256, e3x3=256)
     fire10 = self._fire_layer('fire10', fire9, s1x1=96, e1x1=384, e3x3=384)
     fire11 = self._fire_layer('fire11', fire10, s1x1=96, e1x1=384, e3x3=384)
     dropout11 = sym.Dropout(fire11, p=0.1, name='drop11')
     return sym.Convolution(
         dropout11, name='conv12', num_filter=NUM_OUT_CHANNELS,
         kernel=(3, 3), stride=(1, 1), pad=(1, 1))
Пример #2
0
def ConvFactory(data,
                num_filter,
                kernel,
                stride=(1, 1),
                pad=(0, 0),
                name=None,
                suffix='',
                attr={}):
    conv = mxy.Convolution(data=data,
                           num_filter=num_filter,
                           kernel=kernel,
                           stride=stride,
                           pad=pad,
                           name='conv_%s%s' % (name, suffix))
    bn = mxy.BatchNorm(data=conv,
                       fix_gamma=fix_gamma,
                       eps=eps,
                       momentum=bn_mom,
                       name='bn_%s%s' % (name, suffix))
    act = mxy.Activation(data=bn,
                         act_type='relu',
                         name='relu_%s%s' % (name, suffix),
                         attr=attr)
    return act
Пример #3
0
def SEModule(data, num_filter, name):
    body = sym.Pooling(data=data,
                       global_pool=True,
                       kernel=(7, 7),
                       pool_type='avg',
                       name=name + '_se_pool1')
    body = sym.Convolution(data=body,
                           num_filter=num_filter // 8,
                           kernel=(1, 1),
                           stride=(1, 1),
                           pad=(0, 0),
                           name=name + "_se_conv1")
    body = Act(data=body, act_type="prelu", name=name + '_se_relu1')
    body = sym.Convolution(data=body,
                           num_filter=num_filter,
                           kernel=(1, 1),
                           stride=(1, 1),
                           pad=(0, 0),
                           name=name + "_se_conv2")
    body = sym.Activation(data=body,
                          act_type='sigmoid',
                          name=name + "_se_sigmoid")
    data = sym.broadcast_mul(data, body)
    return data
Пример #4
0
 def _get_activation(self, inputs, activation, **kwargs):
     """Get activation function. Convert if is string"""
     if isinstance(activation, string_types):
         return symbol.Activation(inputs, act_type=activation, **kwargs)
     else:
         return activation(inputs, **kwargs)