MCPcopy Create free account
hub / github.com/apache/singa / prepare

Method prepare

python/singa/sonnx.py:1911–1948  ·  view source on GitHub ↗

parse the ONNX and to create layers Args: model (ModelProto): the loaded ONNX model device (string): CPU or CUDA Returns: a SingaRep instance to stores the layers and weights

(cls, model, device='CPU', **kwargs)

Source from the content-addressed store, hash-verified

1909
1910 @classmethod
1911 def prepare(cls, model, device='CPU', **kwargs):
1912 """
1913 parse the ONNX and to create layers
1914 Args:
1915 model (ModelProto): the loaded ONNX model
1916 device (string): CPU or CUDA
1917 Returns:
1918 a SingaRep instance to stores the layers and weights
1919 """
1920 super(SingaBackend, cls).prepare(model, device, **kwargs)
1921 # optimize and infer the shape of the model
1922 try:
1923 model = onnx.utils.polish_model(model)
1924 except IndexError as err:
1925 model = shape_inference.infer_shapes(model)
1926
1927 # check the opset version and ir version
1928 # SINGA supports opset version(11), ir version(1.6.0 -> 6)
1929 opset_version = None
1930 for imp in model.opset_import:
1931 if not imp.HasField("domain") or imp.domain == "":
1932 opset_version = imp.version
1933 if imp.version > cls._opset_version:
1934 warnings.warn(
1935 "The imported opertor set verion {} is larger than the supported version {}."
1936 .format(imp.version, cls._opset_version))
1937 else:
1938 warnings.warn("Unrecognized operator set {}".format(imp.domain))
1939
1940 if model.ir_version > cls._ir_version:
1941 warnings.warn(
1942 "The imported ir verion {} is larger than the supported version {}."
1943 .format(cls._ir_version, imp.version))
1944
1945 graph = model.graph
1946 params, inputs, outputs, layers = cls._onnx_model_to_singa_ops(
1947 graph, device, opset_version)
1948 return SingaRep(params, inputs, outputs, layers, device)
1949
1950
1951class SingaRep(BackendRep):

Callers 15

_conv2d_helperMethod · 0.80
_relu_helperMethod · 0.80
_avg_pool_helperMethod · 0.80
_softmax_helperMethod · 0.80
_sigmoid_helperMethod · 0.80
_add_helperMethod · 0.80
_concat_helperMethod · 0.80
_matmul_helperMethod · 0.80
_max_pool_helperMethod · 0.80
_batch_norm_helperMethod · 0.80
_linear_helperMethod · 0.80
_gemm_helperMethod · 0.80

Calls 2

SingaRepClass · 0.85

Tested by 15

_conv2d_helperMethod · 0.64
_relu_helperMethod · 0.64
_avg_pool_helperMethod · 0.64
_softmax_helperMethod · 0.64
_sigmoid_helperMethod · 0.64
_add_helperMethod · 0.64
_concat_helperMethod · 0.64
_matmul_helperMethod · 0.64
_max_pool_helperMethod · 0.64
_batch_norm_helperMethod · 0.64
_linear_helperMethod · 0.64
_gemm_helperMethod · 0.64