forked from alibaba/TinyNeuralNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.py
41 lines (32 loc) · 1.09 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import inspect
import sys
from enum import IntEnum
from ..schemas.tflite.schema_generated import ActivationFunctionType, BuiltinOperator
# In Python 3.6, we cannot make ExtendedOperator derive from IntEnum
if sys.version_info >= (3, 7):
bases = (IntEnum,)
else:
bases = ()
class _ExtendedOperatorBase(BuiltinOperator, *bases):
INPUT_NODE = -1
OUTPUT_NODE = -2
CONSTANT_NODE = -3
UNUSED_NODE = -4
BATCH_NORM = -10
GENERIC_CONV = -11
GENERIC_DECONV = -12
def type_name(self):
return self.name.replace('_NODE', '')
# In Python 3.6, the elements in the parent class are not collected in IntEnum,
# so we have to do that dynamically.
if sys.version_info >= (3, 7):
ExtendedOperator = _ExtendedOperatorBase
else:
ExtendedOperator = IntEnum(
'ExtendedOperator', dict(filter(lambda x: not x[0].startswith('__'), inspect.getmembers(_ExtendedOperatorBase)))
)
FUSE_ACTIVATION_MAP = {
BuiltinOperator.RELU: ActivationFunctionType.RELU,
BuiltinOperator.RELU6: ActivationFunctionType.RELU6,
BuiltinOperator.TANH: ActivationFunctionType.TANH,
}