Esempio n. 1
0
def _pad():
    """converting attributes for Pad operator"""
    return AttrCvt(
        op_name='pad',
        transforms={
            'pads': ('pad_width', (0, 0, 0, 0, 0, 0, 0, 0), _pad_sequence_fix),
            'value':'constant_value'})
Esempio n. 2
0
def _batch_norm():
    """converting attributes for BatchNorm operator"""
    return AttrCvt(
        op_name='BatchNorm',
        transforms={'epsilon': 'eps'},
        extras={'cudnn_off': 1},
        ignores=['spatial', 'is_test', 'consumed_inputs'])
Esempio n. 3
0
def _activation(name):
    """converting attributes for LeakyRelu operator"""
    return AttrCvt(
        op_name='LeakyReLU',
        transforms={
            'alpha':'slope'},
        extras={'act_type': name})
Esempio n. 4
0
def _global_pooling(name):
    """Requires kernel attribute which is not present in onnx currently.
    So for now giving default kernel."""
    return AttrCvt(
        op_name='Pooling',
        extras={'global_pool': True,
                'kernel': (1, 1),
                'pool_type': name})
Esempio n. 5
0
def _upsample(name):
    """converting attributes for UpSampling operator"""
    return AttrCvt(op_name=name,
                   transforms={
                       'height_scale': ('scale', 1, _upsample_scale_fix),
                       'mode':
                       ('sample_type', 'nearest', _upsample_restrict_mode),
                       'width_scale': ('scale', 1, _upsample_scale_fix)
                   })
Esempio n. 6
0
def _conv():
    """converting attributes for convolution operator"""
    return AttrCvt(
        op_name='Convolution',
        transforms={
            'kernel_shape': 'kernel',
            'strides': 'stride',
            'dilations': ('dilate', (0, 0)),
            'pads': ('pad', (0, 0), _revert_caffe2_pad),
            'group': ('num_group', 1)},
        custom_check=_dimension_constraint())
Esempio n. 7
0
def _pooling(name):
    """converting attributes for pooling operator"""
    return AttrCvt(
        op_name='Pooling',
        transforms={
            'kernel_shape': 'kernel',
            'strides': 'stride',
            'pads': 'pad'},
        # pooling convention full to match caffe2
        extras={'pool_type': name, 'pooling_convention':'valid'},
        custom_check=_dimension_constraint())
Esempio n. 8
0
def _conv_transpose():
    """converting attributes for deconvolution operator"""
    return AttrCvt(op_name='Deconvolution',
                   transforms={
                       'kernel_shape': 'kernel',
                       'strides': 'stride',
                       'dilations': ('dilate', (0, 0)),
                       'pads': ('pad', (0, 0), _revert_caffe2_pad)
                   },
                   disables=['output_shape'],
                   custom_check=_dimension_constraint())
Esempio n. 9
0
def _pooling(name):
    """converting attributes for pooling operator"""
    return AttrCvt(
        op_name='Pooling',
        transforms={
            'kernel_shape': 'kernel',
            'strides': 'stride',
            'pads': ('pad', (0, 0), _revert_caffe2_pad)
        },
        # pooling convention full to match caffe2
        extras={
            'pool_type': name,
            'pooling_convention': 'full'
        },
        ignores=['dilations'],
        custom_check=_dimension_constraint())
Esempio n. 10
0
def _elemwise(name):
    """converting attributes for add operator"""
    return AttrCvt(
        op_name=_math_name_picker(name),
        disables=['axis'],
        ignores=['broadcast'])
Esempio n. 11
0
def _global_pooling(name):
    """Requires kernel attribute which is not present in onnx currently.
    So for now giving default kernel."""
    return AttrCvt(
        op_name='Pooling',
        extras={'global_pool': True,
                'kernel': (1, 1),
                'pool_type': name})

# compatible operators that do NOT require any conversion.
_identity_list = []

# _convert_map defines maps of name to converter functor(callable)
_convert_map = {
    # defs/experimental
    'FC'            : AttrCvt('FullyConnected', ignores=['axis', 'axis_w']),

    # defs/generator
    'Constant': Renamer('identity'),
    'RandomUniform' : AttrCvt('random_uniform', ignores=['seed']),
    'RandomNormal'  : AttrCvt('random_normal', {'mean':'loc'}, ignores=['seed']),
    'RandomUniformLike' : AttrCvt('random_uniform', ignores=['seed']),
    'RandomNormalLike': AttrCvt('random_normal', {'mean':'loc'}, ignores=['seed']),

    # defs/logical

    # defs/math
    'Add'           : _elemwise('add'),
    'Sub'           : _elemwise('sub'),
    'Mul'           : _elemwise('mul'),
    'Div'           : _elemwise('div'),
Esempio n. 12
0
def _batch_norm():
    """converting attributes for BatchNorm operator"""
    return AttrCvt(op_name='BatchNorm',
                   transforms={'epsilon': ('eps', (1e-5), _change_eps_cudnn)},
                   ignores=['spatial', 'is_test', 'consumed_inputs'])
Esempio n. 13
0
                   transforms={
                       'height_scale': ('scale', 1, _upsample_scale_fix),
                       'mode':
                       ('sample_type', 'nearest', _upsample_restrict_mode),
                       'width_scale': ('scale', 1, _upsample_scale_fix)
                   })


# compatible operators that do NOT require any conversion.
_identity_list = []

# _convert_map defines maps of name to converter functor(callable)
_convert_map = {
    # defs/experimental
    'FC':
    AttrCvt('FullyConnected', ignores=['axis', 'axis_w']),

    # defs/generator
    'Constant':
    Renamer('identity'),
    'RandomUniform':
    AttrCvt('random_uniform', ignores=['seed']),
    'RandomNormal':
    AttrCvt('random_normal', {'mean': 'loc'}, ignores=['seed']),
    'RandomUniformLike':
    AttrCvt('random_uniform', ignores=['seed']),
    'RandomNormalLike':
    AttrCvt('random_normal', {'mean': 'loc'}, ignores=['seed']),

    # defs/logical