From e540cbaac425ee851ac1b7acf36c272ce7c7ee1a Mon Sep 17 00:00:00 2001 From: liutuo Date: Tue, 5 Jun 2018 17:50:12 +0800 Subject: [PATCH] fix scaler eltwise op tranform bug --- mace/ops/eltwise.h | 2 +- mace/ops/eltwise_test.cc | 8 ++++---- mace/python/tools/converter_tool/base_converter.py | 1 + .../tools/converter_tool/tensorflow_converter.py | 13 +++++++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/mace/ops/eltwise.h b/mace/ops/eltwise.h index 66c505fa..9cc800bf 100644 --- a/mace/ops/eltwise.h +++ b/mace/ops/eltwise.h @@ -30,7 +30,7 @@ class EltwiseOp : public Operator { static_cast(OperatorBase::GetOptionalArg( "type", static_cast(kernels::EltwiseType::NONE))), OperatorBase::GetRepeatedArgs("coeff"), - OperatorBase::GetOptionalArg("x", 1.0)) {} + OperatorBase::GetOptionalArg("value", 1.0)) {} MaceStatus Run(StatsFuture *future) override { const Tensor *input0 = this->Input(0); diff --git a/mace/ops/eltwise_test.cc b/mace/ops/eltwise_test.cc index e3cbb2de..e8fd81cf 100644 --- a/mace/ops/eltwise_test.cc +++ b/mace/ops/eltwise_test.cc @@ -40,7 +40,7 @@ void SimpleTensorScalar(const kernels::EltwiseType type, OpDefBuilder("Eltwise", "EltwiseTest") .Input("TInput") .AddIntArg("type", static_cast(type)) - .AddFloatArg("x", x) + .AddFloatArg("value", x) .Output("TOutput") .Finalize(net.NewOperatorDef()); // Run @@ -52,7 +52,7 @@ void SimpleTensorScalar(const kernels::EltwiseType type, OpDefBuilder("Eltwise", "EltwiseTest") .Input("InputImg") .AddIntArg("type", static_cast(type)) - .AddFloatArg("x", x) + .AddFloatArg("value", x) .Output("OutputImg") .Finalize(net.NewOperatorDef()); @@ -321,7 +321,7 @@ void RandomTensorScalar(const kernels::EltwiseType type, OpDefBuilder("Eltwise", "EltwiseTest") .Input("TInput") .AddIntArg("type", static_cast(type)) - .AddFloatArg("x", 0.1) + .AddFloatArg("value", 0.1) .Output("TOutput") .Finalize(net.NewOperatorDef()); // Run @@ -336,7 +336,7 @@ void RandomTensorScalar(const kernels::EltwiseType type, OpDefBuilder("Eltwise", "EltwiseTest") .Input("InputImg") .AddIntArg("type", static_cast(type)) - .AddFloatArg("x", 0.1) + .AddFloatArg("value", 0.1) .Output("OutputImg") .AddIntArg("T", static_cast(DataTypeToEnum::value)) .Finalize(net.NewOperatorDef()); diff --git a/mace/python/tools/converter_tool/base_converter.py b/mace/python/tools/converter_tool/base_converter.py index be6e6752..0a56239e 100644 --- a/mace/python/tools/converter_tool/base_converter.py +++ b/mace/python/tools/converter_tool/base_converter.py @@ -139,6 +139,7 @@ class MaceKeyword(object): mace_shape_str = 'shape' mace_winograd_filter_transformed = 'is_filter_transformed' mace_device = 'device' + mace_value_str = 'value' class TransformerRule(Enum): diff --git a/mace/python/tools/converter_tool/tensorflow_converter.py b/mace/python/tools/converter_tool/tensorflow_converter.py index 19674f37..0eea81c0 100644 --- a/mace/python/tools/converter_tool/tensorflow_converter.py +++ b/mace/python/tools/converter_tool/tensorflow_converter.py @@ -309,6 +309,19 @@ class TensorflowConverter(base_converter.ConverterInterface): type_arg.name = MaceKeyword.mace_element_type_str type_arg.i = self.eltwise_type[tf_op.type].value + if len(tf_op.inputs[0].shape) == 0: + value_arg = op.arg.add() + value_arg.name = MaceKeyword.mace_value_str + value_arg.f = tf_op.inputs[0].eval().astype(np.float32) + self._skip_tensor.add(tf_op.inputs[0].name) + del op.input[0] + elif len(tf_op.inputs[1].shape) == 0: + value_arg = op.arg.add() + value_arg.name = MaceKeyword.mace_value_str + value_arg.f = tf_op.inputs[1].eval().astype(np.float32) + self._skip_tensor.add(tf_op.inputs[1].name) + del op.input[1] + def convert_biasadd(self, tf_op): op = self.convert_general_op(tf_op) op.type = MaceOp.BiasAdd.name -- GitLab