Exemple #1
0
 def __init__(self, C, stride, ops_cands):
     """Init MixedOp."""
     super(MixedOp, self).__init__()
     if not isinstance(ops_cands, list):
         # train
         self.add_module(ops_cands, OPS[ops_cands](C, stride, True))
     else:
         # search
         for primitive in ops_cands:
             op = OPS[primitive](C, stride, False)
             if 'pool' in primitive:
                 op = Seq(op, ops.BatchNorm2d(C, affine=False))
             self.add_module(primitive, op)
Exemple #2
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# MIT License for more details.

"""Import all torch operators."""
from zeus.common import ClassType, ClassFactory
from zeus.modules.operators import Seq, SeparatedConv, DilConv, GAPConv1x1, conv1X1, \
    conv3x3, conv5x5, conv7x7, FactorizedReduce
from zeus.modules.operators import ops

OPS = {
    'none': lambda C, stride, affine, repeats=1: ops.Zero(stride),
    'avg_pool_3x3': lambda C, stride, affine, repeats=1: ops.AvgPool2d(
        3, stride=stride, padding=1, count_include_pad=False),
    'max_pool_3x3': lambda C, stride, affine, repeats=1: ops.MaxPool2d(
        3, stride=stride, padding=1),
    'global_average_pool': lambda C, stride, affine, repeats=1: Seq(GAPConv1x1(C, C)),
    'skip_connect': lambda C, stride, affine, repeats=1: ops.Identity() if stride == 1 else FactorizedReduce(
        C, C, affine=affine),
    'sep_conv_3x3': lambda C, stride, affine, repeats=1: SeparatedConv(C, C, 3, stride, 1, affine=affine),
    'sep_conv_5x5': lambda C, stride, affine, repeats=1: SeparatedConv(C, C, 5, stride, 2, affine=affine),
    'sep_conv_7x7': lambda C, stride, affine, repeats=1: SeparatedConv(C, C, 7, stride, 3, affine=affine),
    'dil_conv_3x3': lambda C, stride, affine, repeats=1: DilConv(C, C, 3, stride, 2, 2, affine=affine),
    'dil_conv_5x5': lambda C, stride, affine, repeats=1: DilConv(C, C, 5, stride, 4, 2, affine=affine),
    'conv_7x1_1x7': lambda C, stride, affine, repeats=1: Seq(
        ops.Relu(inplace=False),
        ops.Conv2d(C, C, (1, 7), stride=(1, stride), padding=(0, 3), bias=False),
        ops.Conv2d(C, C, (7, 1), stride=(stride, 1), padding=(3, 0), bias=False),
        ops.BatchNorm2d(C, affine=affine)),
    'conv1x1': lambda C, stride, affine, repeats=1: Seq(
        conv1X1(C, C, stride=stride),
        ops.BatchNorm2d(C, affine=affine),
Exemple #3
0
from zeus.common import ClassType, ClassFactory
from zeus.modules.operators import Seq, SeparatedConv, DilConv, GAPConv1x1, conv1X1, \
    conv3x3, conv5x5, conv7x7, FactorizedReduce
from zeus.modules.operators import ops

OPS = {
    'none':
    lambda C, stride, affine, repeats=1: ops.Zero(stride),
    'avg_pool_3x3':
    lambda C, stride, affine, repeats=1: ops.AvgPool2d(
        3, stride=stride, padding=1, count_include_pad=False),
    'max_pool_3x3':
    lambda C, stride, affine, repeats=1: ops.MaxPool2d(
        3, stride=stride, padding=1),
    'global_average_pool':
    lambda C, stride, affine, repeats=1: Seq(GAPConv1x1(C, C)),
    'skip_connect':
    lambda C, stride, affine, repeats=1: ops.Identity()
    if stride == 1 else FactorizedReduce(C, C, affine=affine),
    'sep_conv_3x3':
    lambda C, stride, affine, repeats=1: SeparatedConv(
        C, C, 3, stride, 1, affine=affine),
    'sep_conv_5x5':
    lambda C, stride, affine, repeats=1: SeparatedConv(
        C, C, 5, stride, 2, affine=affine),
    'sep_conv_7x7':
    lambda C, stride, affine, repeats=1: SeparatedConv(
        C, C, 7, stride, 3, affine=affine),
    'dil_conv_3x3':
    lambda C, stride, affine, repeats=1: DilConv(
        C, C, 3, stride, 2, 2, affine=affine),