diff --git a/docker/mace-dev-lite/Dockerfile b/docker/mace-dev-lite/Dockerfile index 29c36b108f4ad87efb5ecefe60318593baba7958..70f94ba8e7458173f0c34d24dd728cd86fded1e9 100644 --- a/docker/mace-dev-lite/Dockerfile +++ b/docker/mace-dev-lite/Dockerfile @@ -136,7 +136,7 @@ RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors torchvision==0.2.2.post3 RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \ - onnx==1.3.0 \ + onnx==1.5.0 \ onnx-tf==1.2.0 RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \ diff --git a/docker/mace-dev/Dockerfile b/docker/mace-dev/Dockerfile index 23c98b3915b2c6d401ef22b5d61bb7316b646d4a..8bb31a7d3a33c4c4d886f170c54fd7ca3d0b6d7d 100644 --- a/docker/mace-dev/Dockerfile +++ b/docker/mace-dev/Dockerfile @@ -106,7 +106,7 @@ RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors torchvision==0.2.2.post3 RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \ - onnx==1.3.0 \ + onnx==1.5.0 \ onnx-tf==1.2.0 RUN pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \ diff --git a/docs/installation/env_requirement.rst b/docs/installation/env_requirement.rst index 4a599ec523e31413cf2bd7c169782bba488760d3..465072a125fe9ea98748a61e7d6e9792e0529f15 100644 --- a/docs/installation/env_requirement.rst +++ b/docs/installation/env_requirement.rst @@ -76,7 +76,7 @@ Optional dependencies - pip install filelock==3.0.0 - Required by run on Android * - ONNX - - pip install onnx==1.3.0 + - pip install onnx==1.5.0 - Required by ONNX model For python dependencies, diff --git a/include/mace/port/file_system.h b/include/mace/port/file_system.h index 4de18fbbb90a0d9a89c63063ae38c287ebc9eaad..2117faea616a895807367967a2e784085c3efd73 100644 --- a/include/mace/port/file_system.h +++ b/include/mace/port/file_system.h @@ -15,6 +15,7 @@ #ifndef MACE_PORT_FILE_SYSTEM_H_ #define MACE_PORT_FILE_SYSTEM_H_ +#include #include #include diff --git a/mace/python/tools/converter_tool/onnx_converter.py b/mace/python/tools/converter_tool/onnx_converter.py index a024aed87df6969da1cfd2bbf483b7c725c4884a..b4a8e291c197b876f585e733b6bea9f8af9c00d1 100644 --- a/mace/python/tools/converter_tool/onnx_converter.py +++ b/mace/python/tools/converter_tool/onnx_converter.py @@ -337,7 +337,7 @@ class OnnxConverter(base_converter.ConverterInterface): OnnxOpType.Conv.name: self.convert_conv2d, OnnxOpType.ConvTranspose.name: self.convert_deconv, OnnxOpType.DepthToSpace.name: self.convert_depth_space, - OnnxOpType.Dropout.name: self.convert_identity, + OnnxOpType.Dropout.name: self.convert_dropout, OnnxOpType.DimRange.name: self.convert_dim_range, OnnxOpType.Div.name: self.convert_eltwise, OnnxOpType.Equal.name: self.convert_eltwise, @@ -369,6 +369,7 @@ class OnnxConverter(base_converter.ConverterInterface): OnnxOpType.Relu.name: self.convert_activation, OnnxOpType.Reshape.name: self.convert_reshape, OnnxOpType.Reciprocal.name: self.convert_eltwise, + OnnxOpType.ReduceMean.name: self.convert_reduce, OnnxOpType.Scale.name: self.convert_eltwise, OnnxOpType.Sigmoid.name: self.convert_activation, OnnxOpType.Slice.name: self.convert_slice, @@ -396,6 +397,8 @@ class OnnxConverter(base_converter.ConverterInterface): ir_version = onnx_model.ir_version opset_imp = onnx_model.opset_import + onnx.checker.check_model(onnx_model) + self._isKaldi = False polish_available = True @@ -404,7 +407,7 @@ class OnnxConverter(base_converter.ConverterInterface): domain = imp.domain version = imp.version print("constains ops domain: ", domain, "version:", version) - if 'kaldi2onnx' in domain: + if 'kaldi' in domain: polish_available = False self._data_format = DataFormat.NONE self._isKaldi = True @@ -656,14 +659,13 @@ class OnnxConverter(base_converter.ConverterInterface): def convert_concat(self, node): op = self.convert_general_op(node) op.type = MaceOp.Concat.name - axis_value = 1 - if node.op_type == OnnxOpType.Concat.name: + if self._isKaldi is False: mace_check('axis' in node.attrs, 'Concat op should have axis attribute.') axis_value = node.attrs['axis'] mace_check(axis_value == 1 or axis_value == -3, "only support concat at channel dimension") - elif node.op_type == OnnxOpType.Append.name: + else: axis_value = -1 axis_arg = op.arg.add() axis_arg.name = MaceKeyword.mace_axis_str @@ -789,6 +791,12 @@ class OnnxConverter(base_converter.ConverterInterface): axes_arg.name = 'axes' axes_arg.ints.extend([-1]) + def convert_dropout(self, node): + op = self.convert_general_op(node) + op.type = MaceOp.Identity.name + del op.output[1:] + del op.output_shape[1:] + def convert_dynamic_lstm(self, node): op = self.convert_general_op(node) op.type = MaceOp.DynamicLSTM.name @@ -1068,6 +1076,9 @@ class OnnxConverter(base_converter.ConverterInterface): axis_arg.i = value def convert_gemm(self, node): + if self._isKaldi: + self.convert_affine(node) + return # only supports FullyConnected Style Gemm for now. trans_a = node.attrs['transA'] if 'transA' in node.attrs else 0 trans_b = node.attrs['transB'] if 'transB' in node.attrs else 0 diff --git a/mace/utils/statistics.cc b/mace/utils/statistics.cc index 7ff43664ddb525b944efa7153d034861980ba793..924b3a71b233c87c4bd5520f0cdab73a91ec9f8f 100644 --- a/mace/utils/statistics.cc +++ b/mace/utils/statistics.cc @@ -131,9 +131,6 @@ int64_t StatMACs(const std::string &op_type, output_shape.end(), 1, std::multiplies()); - } else if (op_type == "DynamicLSTM") { - macs = output_shape[0] * (filter_shape[0] * filter_shape[1] - + output_shape[1] * filter_shape[0] / 4); } return macs; } diff --git a/setup/optionals.txt b/setup/optionals.txt index 9418795047a500b1b5c67fb6bd0c0f48b9ab68c7..2c0c3427d0ab36fefa7ec9fa7076bad1a0029231 100644 --- a/setup/optionals.txt +++ b/setup/optionals.txt @@ -1,4 +1,4 @@ tensorflow>=1.8.0 scipy>=1.0.0 filelock>=3.0.0 -onnx>=1.3.0 \ No newline at end of file +onnx>=1.5.0 \ No newline at end of file