onnx_directly_map.py 3.0 KB
Newer Older
C
update  
channingss 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#   Copyright (c) 2019  PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from collections import OrderedDict as _dict
C
channingss 已提交
16
import numpy as _np
C
update  
channingss 已提交
17 18 19 20 21 22 23 24 25 26

default_op_mapping_field_values = _dict()
default_op_mapping_field_values['FLUID_OP'] = ''
default_op_mapping_field_values['FLUID_INPUT_ARGS'] = None
default_op_mapping_field_values['FLUID_OUTPUT_ARGS'] = None
default_op_mapping_field_values['ATTR_MAPPING'] = dict()
default_op_mapping_field_values['DEFAULTS'] = dict()
default_op_mapping_field_values['INPUT_PERM'] = None
default_op_mapping_field_values['OUTPUT_PERM'] = None
default_op_mapping_field_values['FILL_NAME_FIELD'] = True
C
channingss 已提交
27

C
update  
channingss 已提交
28 29
default_op_mapping = {
    'Shape': ['shape', ['X'], ['Out']],
C
channingss 已提交
30
    'Clip': [
31 32 33 34 35
        'clip', ['X'], ['Out'], dict(), dict(
            min=(_np.asarray(
                [255, 255, 127, 255], dtype=_np.uint8).view(_np.float32)[0]),
            max=(_np.asarray(
                [255, 255, 127, 127], dtype=_np.uint8).view(_np.float32)[0]), )
C
channingss 已提交
36
    ],
C
Channingss 已提交
37
    'Erf': ['erf', ['X'], ['Out']],
C
channingss 已提交
38
    'Ceil': ['ceil', ['X'], ['Out']],
C
channingss 已提交
39
    'ReduceMean': [
40 41
        'reduce_mean', ['X'], ['Out'], dict(
            axes='dim', keepdims='keep_dim'), dict(keep_dim=1)
C
channingss 已提交
42
    ],
C
channingss 已提交
43
    'ReduceSum': [
44 45
        'reduce_sum', ['X'], ['Out'], dict(
            axes='dim', keepdims='keep_dim'), dict(keep_dim=1)
C
channingss 已提交
46
    ],
C
channingss 已提交
47
    'ReduceMin': [
48 49 50 51 52 53
        'reduce_min', ['X'], ['Out'], dict(
            axes='dim', keepdims='keep_dim'), dict(keep_dim=1)
    ],
    'ReduceMax': [
        'reduce_max', ['X'], ['Out'], dict(
            axes='dim', keepdims='keep_dim'), dict(keep_dim=1)
C
channingss 已提交
54
    ],
C
channingss 已提交
55 56
    #active function
    'Relu': ['relu', ['X'], ['Out']],
57 58
    'LeakyRelu': ['leaky_relu', ['X'], ['Out'], dict(), dict(alpha=.01)],
    'Elu': ['elu', ['X'], ['Out'], dict(), dict(alpha=1.)],
C
channingss 已提交
59
    'ThresholdedRelu': [
60
        'thresholded_relu', ['X'], ['Out'], dict(alpha='threshold'),
C
channingss 已提交
61 62
        dict(alpha=1.)
    ],
C
channingss 已提交
63
    'Tanh': ['tanh', ['X'], ['Out']],
C
channingss 已提交
64 65
    'Sigmoid': ['sigmoid', ['X'], ['Out']],
    'HardSigmoid': [
66 67 68
        'hard_sigmoid', ['X'], ['Out'], dict(
            alpha='slope', beta='offset'), dict(
                slope=.2, offset=.5)
C
channingss 已提交
69 70 71 72
    ],
    'Softsign': ['softsign', ['X'], ['Out']],
    'Softplus': ['softplus', ['X'], ['Out']],
    'Exp': ['exp', ['X'], ['Out']],
73
    'Softmax': ['softmax', ['X'], ['Out'], dict(), dict(axis=1)],
C
channingss 已提交
74
    'Sqrt': ['sqrt', ['X'], ['Out']],
C
channings 已提交
75
    'Floor': ['floor', ['X'], ['Out']],
C
channings 已提交
76
    'Abs': ['abs', ['X'], ['Out']],
C
channingss 已提交
77 78
}

C
update  
channingss 已提交
79
default_ioa_constraint = {
80 81
    'Gather': [(lambda i, o, a: a.get('axis', 0) == 0,
                'only axis = 0 is supported')],
C
update  
channingss 已提交
82
}