You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

constant.py 2.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Copyright 2020 Huawei Technologies Co., Ltd.All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """Constant definition."""
  16. from enum import Enum, unique
  17. SEPARATOR_IN_ONNX_OP = "::"
  18. SEPARATOR_IN_SCOPE = "/"
  19. SEPARATOR_BTW_NAME_AND_ID = "_"
  20. SEPARATOR_TITLE_AND_CONTENT_IN_CONSTRUCT = "="
  21. LINK_IN_SCOPE = "-"
  22. LEFT_BUCKET = "["
  23. RIGHT_BUCKET = "]"
  24. BLANK_SYM = " "
  25. FIRST_LEVEL_INDENT = BLANK_SYM * 4
  26. SECOND_LEVEL_INDENT = BLANK_SYM * 8
  27. NEW_LINE = "\n"
  28. ONNX_TYPE_INT = 2
  29. ONNX_TYPE_INTS = 7
  30. ONNX_TYPE_FLOAT = 1
  31. ONNX_TYPE_FLOATS = 6
  32. ONNX_TYPE_STRING = 3
  33. DYNAMIC_SHAPE = -1
  34. SCALAR_WITHOUT_SHAPE = 0
  35. UNKNOWN_DIM_VAL = "unk__001"
  36. ONNX_MIN_VER = "1.8.0"
  37. TF2ONNX_MIN_VER = "1.7.1"
  38. ONNXRUNTIME_MIN_VER = "1.5.2"
  39. BINARY_HEADER_PYTORCH_FILE = \
  40. b'\x80\x02\x8a\nl\xfc\x9cF\xf9 j\xa8P\x19.\x80\x02M\xe9\x03.\x80\x02}q\x00(X\x10\x00\x00\x00'
  41. TENSORFLOW_MODEL_SUFFIX = "pb"
  42. BINARY_HEADER_PYTORCH_BITS = 32
  43. ARGUMENT_LENGTH_LIMIT = 512
  44. EXPECTED_NUMBER = 1
  45. MIN_SCOPE_LENGTH = 2
  46. NO_CONVERTED_OPERATORS = [
  47. "onnx::Constant"
  48. ]
  49. @unique
  50. class CodeFormatConfig(Enum):
  51. PEP8 = "pep8"
  52. @unique
  53. class NodeType(Enum):
  54. MODULE = "module"
  55. OPERATION = "operation"
  56. CLASS = "class"
  57. FUNC = "func"
  58. INPUTS = "DataInput"
  59. @unique
  60. class InputType(Enum):
  61. TENSOR = "tensor"
  62. LIST = "list"
  63. @unique
  64. class FrameworkType(Enum):
  65. PYTORCH = 0
  66. TENSORFLOW = 1
  67. UNKNOWN = 2
  68. def get_imported_module():
  69. """
  70. Generate imported module header.
  71. Returns:
  72. str, imported module.
  73. """
  74. return f"import numpy as np{NEW_LINE}" \
  75. f"import mindspore{NEW_LINE}" \
  76. f"from mindspore import nn{NEW_LINE}" \
  77. f"from mindspore import Tensor{NEW_LINE}" \
  78. f"from mindspore.ops import operations as P{NEW_LINE * 3}"