diff --git a/src/common/types.cpp b/src/common/types.cpp index 965ab8c4a99d9737efd3b61afb8a4a071c385787..a0a3b6954ebd3cf32519fa3d91012d4e3be170fa 100644 --- a/src/common/types.cpp +++ b/src/common/types.cpp @@ -59,6 +59,9 @@ const char *G_OP_TYPE_PRELU = "prelu"; const char *G_OP_TYPE_LOOKUP_TABLE = "lookup_table"; const char *G_OP_TYPE_GRU = "gru"; const char *G_OP_TYPE_CRF = "crf_decoding"; +const char *G_OP_TYPE_BILINEAR_INTERP = "bilinear_interp"; +const char *G_OP_TYPE_FLATTEN = "flatten"; +const char *G_OP_TYPE_SHAPE = "shape"; std::unordered_map< std::string, std::pair, std::vector>> @@ -105,6 +108,9 @@ std::unordered_map< {{"Input", "H0", "Weight", "Bias"}, {"BatchGate", "BatchResetHiddenPrev", "BatchHidden", "Hidden"}}}, {G_OP_TYPE_CRF, {{"Emission", "Transition", "Label"}, {"ViterbiPath"}}}, + {G_OP_TYPE_BILINEAR_INTERP, {{"OutSize", "X"}, {"Out"}}}, + {G_OP_TYPE_FLATTEN, {{"X"}, {"Out"}}}, + {G_OP_TYPE_SHAPE, {{"Input"}, {"Out"}}}, {G_OP_TYPE_CONV_TRANSPOSE, {{"Input"}, {"Output"}}}}; } // namespace paddle_mobile diff --git a/src/operators/bilinear_interp_op.cpp b/src/operators/bilinear_interp_op.cpp new file mode 100644 index 0000000000000000000000000000000000000000..319cc2cea68ade29e192d45a98f64d6c7d5601ed --- /dev/null +++ b/src/operators/bilinear_interp_op.cpp @@ -0,0 +1,39 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef BILINEAR_INTERP_OP + +#include "operators/bilinear_interp_op.h" + +namespace paddle_mobile { +namespace operators { +template +void BilinearOp::InferShape() const { + // todo check + this->param_.Out()->Resize(this->param_.InputX()->dims()); +} + +} // namespace operators +} // namespace paddle_mobile + +namespace ops = paddle_mobile::operators; +#ifdef PADDLE_MOBILE_CPU +REGISTER_OPERATOR_CPU(bilinear_interp, ops::BilinearOp); +#endif +#ifdef PADDLE_MOBILE_MALI_GPU +#endif +#ifdef PADDLE_MOBILE_FPGA +#endif + +#endif diff --git a/src/operators/bilinear_interp_op.h b/src/operators/bilinear_interp_op.h new file mode 100644 index 0000000000000000000000000000000000000000..dbbf24eeac7a900d49f49242fddb8e568968dddc --- /dev/null +++ b/src/operators/bilinear_interp_op.h @@ -0,0 +1,61 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef BILINEAR_INTERP_OP + +#pragma once + +#include + +#include "framework/operator.h" +#include "operators/kernel/bilinear_interp_kernel.h" +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +using paddle_mobile::framework::Tensor; + +template +class BilinearOp : public framework::OperatorWithKernel< + DeviceType, BilinearInterpParam, + operators::BilinearInterpKernel> { + public: + BilinearOp(const std::string &type, const VariableNameMap &inputs, + const VariableNameMap &outputs, + const framework::AttributeMap &attrs, + std::shared_ptr scope) + : framework::OperatorWithKernel< + DeviceType, BilinearInterpParam, + operators::BilinearInterpKernel>( + type, inputs, outputs, attrs, scope) {} + + using framework::OperatorWithKernel< + DeviceType, BilinearInterpParam, + operators::BilinearInterpKernel>::OperatorWithKernel; + void InferShape() const override; +}; + +} // namespace operators +} // namespace paddle_mobile + +#ifdef PADDLE_MOBILE_CPU +USE_OP_CPU(bilinear_interp); +#endif +#ifdef PADDLE_MOBILE_MALI_GPU +#endif +#ifdef PADDLE_MOBILE_FPGA +#endif + +#endif diff --git a/src/operators/flatten_op.cpp b/src/operators/flatten_op.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ebc0e4c526696b0cd62a241850dd13deeb271b33 --- /dev/null +++ b/src/operators/flatten_op.cpp @@ -0,0 +1,39 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef FLATTEN_OP + +#include "operators/flatten_op.h" + +namespace paddle_mobile { +namespace operators { +template +void FlattenOp::InferShape() const { + // todo check + this->param_.Out()->Resize(this->param_.InputX()->dims()); +} + +} // namespace operators +} // namespace paddle_mobile + +namespace ops = paddle_mobile::operators; +#ifdef PADDLE_MOBILE_CPU +REGISTER_OPERATOR_CPU(flatten, ops::FlattenOp); +#endif +#ifdef PADDLE_MOBILE_MALI_GPU +#endif +#ifdef PADDLE_MOBILE_FPGA +#endif + +#endif diff --git a/src/operators/flatten_op.h b/src/operators/flatten_op.h new file mode 100644 index 0000000000000000000000000000000000000000..279f2e4aa3ff8efa6617bf9ee3bde7164c8a391a --- /dev/null +++ b/src/operators/flatten_op.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef FLATTEN_OP + +#pragma once + +#include + +#include "framework/operator.h" +#include "operators/kernel/flatten_kernel.h" +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +using paddle_mobile::framework::Tensor; + +template +class FlattenOp : public framework::OperatorWithKernel< + DeviceType, FlattenParam, + operators::FlattenKernel> { + public: + FlattenOp(const std::string &type, const VariableNameMap &inputs, + const VariableNameMap &outputs, + const framework::AttributeMap &attrs, + std::shared_ptr scope) + : framework::OperatorWithKernel, + operators::FlattenKernel>( + type, inputs, outputs, attrs, scope) {} + + using framework::OperatorWithKernel< + DeviceType, FlattenParam, + operators::FlattenKernel>::OperatorWithKernel; + void InferShape() const override; +}; + +} // namespace operators +} // namespace paddle_mobile + +#ifdef PADDLE_MOBILE_CPU +USE_OP_CPU(flatten); +#endif +#ifdef PADDLE_MOBILE_MALI_GPU +#endif +#ifdef PADDLE_MOBILE_FPGA +#endif + +#endif diff --git a/src/operators/kernel/arm/bilinear_interp_kernel.cpp b/src/operators/kernel/arm/bilinear_interp_kernel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea5ff627d7ea2e0fa5434f9f7fc9f5ec44ce60a7 --- /dev/null +++ b/src/operators/kernel/arm/bilinear_interp_kernel.cpp @@ -0,0 +1,38 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ +#pragma once + +#ifdef BILINEAR_INTERP_OP + +#include "operators/kernel/bilinear_interp_kernel.h" +#include "operators/kernel/central-arm-func/bilinear_interp_arm_func.h" + +namespace paddle_mobile { +namespace operators { + +template <> +bool BilinearInterpKernel::Init(BilinearInterpParam *param) { + return true; +} + +template <> +void BilinearInterpKernel::Compute( + const BilinearInterpParam ¶m) const { + BilinearInterpCompute(param); +} + +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/kernel/arm/flatten_kernel.cpp b/src/operators/kernel/arm/flatten_kernel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6866b740aa945852050e7fca4991489f48435150 --- /dev/null +++ b/src/operators/kernel/arm/flatten_kernel.cpp @@ -0,0 +1,37 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ +#pragma once + +#ifdef FLATTEN_OP + +#include "operators/kernel/flatten_kernel.h" +#include "operators/kernel/central-arm-func/flatten_arm_func.h" + +namespace paddle_mobile { +namespace operators { + +template <> +bool FlattenKernel::Init(FlattenParam *param) { + return true; +} + +template <> +void FlattenKernel::Compute(const FlattenParam ¶m) const { + FlattenCompute(param); +} + +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/kernel/arm/shape_kernel.cpp b/src/operators/kernel/arm/shape_kernel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..69fd4021fe3110a7cea02a67443939048c1dddab --- /dev/null +++ b/src/operators/kernel/arm/shape_kernel.cpp @@ -0,0 +1,37 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ +#pragma once + +#ifdef SHAPE_OP + +#include "operators/kernel/shape_kernel.h" +#include "operators/kernel/central-arm-func/shape_arm_func.h" + +namespace paddle_mobile { +namespace operators { + +template <> +bool ShapeKernel::Init(ShapeParam *param) { + return true; +} + +template <> +void ShapeKernel::Compute(const ShapeParam ¶m) const { + ShapeCompute(param); +} + +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/kernel/arm/split_kernel.cpp b/src/operators/kernel/arm/split_kernel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..292b5bda99a524615df4a8552e5617fd4470d8a0 --- /dev/null +++ b/src/operators/kernel/arm/split_kernel.cpp @@ -0,0 +1,37 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ +#pragma once + +#ifdef SPLIT_OP + +#include "operators/kernel/split_kernel.h" +#include "operators/kernel/central-arm-func/split_arm_func.h" + +namespace paddle_mobile { +namespace operators { + +template <> +bool SplitKernel::Init(SplitParam *param) { + return true; +} + +template <> +void SplitKernel::Compute(const SplitParam ¶m) const { + SplitCompute(param); +} + +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/kernel/bilinear_interp_kernel.h b/src/operators/kernel/bilinear_interp_kernel.h new file mode 100644 index 0000000000000000000000000000000000000000..ac3dfcb16190315f72dc60da54c4f944874e4458 --- /dev/null +++ b/src/operators/kernel/bilinear_interp_kernel.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef BILINEAR_INTERP_OP + +#pragma once + +#include + +#include "framework/operator.h" +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +template +class BilinearInterpKernel + : public framework::OpKernelBase> { + public: + void Compute(const BilinearInterpParam& param) const; + bool Init(BilinearInterpParam* param); +}; +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/kernel/central-arm-func/bilinear_interp_arm_func.h b/src/operators/kernel/central-arm-func/bilinear_interp_arm_func.h new file mode 100644 index 0000000000000000000000000000000000000000..068d33e46a8d425225bf9983c47829444a46f8af --- /dev/null +++ b/src/operators/kernel/central-arm-func/bilinear_interp_arm_func.h @@ -0,0 +1,30 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef BILINEAR_INTERP_OP +#pragma once + +#include +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +template +void BilinearInterpCompute(const BilinearInterpParam& param) {} + +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/kernel/central-arm-func/flatten_arm_func.h b/src/operators/kernel/central-arm-func/flatten_arm_func.h new file mode 100644 index 0000000000000000000000000000000000000000..526db3abd4a249531f3cccea62aad75722f5b4b0 --- /dev/null +++ b/src/operators/kernel/central-arm-func/flatten_arm_func.h @@ -0,0 +1,30 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef FLATTEN_OP +#pragma once + +#include +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +template +void FlattenCompute(const FlattenParam& param) {} + +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/kernel/central-arm-func/shape_arm_func.h b/src/operators/kernel/central-arm-func/shape_arm_func.h new file mode 100644 index 0000000000000000000000000000000000000000..846f4c474ab067f02cfd809a876abc7b62ab784f --- /dev/null +++ b/src/operators/kernel/central-arm-func/shape_arm_func.h @@ -0,0 +1,30 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef SHAPE_OP +#pragma once + +#include +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +template +void ShapeCompute(const ShapeParam& param) {} + +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/kernel/central-arm-func/split_arm_func.h b/src/operators/kernel/central-arm-func/split_arm_func.h new file mode 100644 index 0000000000000000000000000000000000000000..77c1c9ed55e042de91ed41ccbde1b3a01eebe212 --- /dev/null +++ b/src/operators/kernel/central-arm-func/split_arm_func.h @@ -0,0 +1,30 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef SPLIT_OP +#pragma once + +#include +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +template +void SplitCompute(const SplitParam& param) {} + +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/kernel/flatten_kernel.h b/src/operators/kernel/flatten_kernel.h new file mode 100644 index 0000000000000000000000000000000000000000..80d66ccf87c21532c8b4590d992f5bccbe4f00dc --- /dev/null +++ b/src/operators/kernel/flatten_kernel.h @@ -0,0 +1,37 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef FLATTEN_OP + +#pragma once + +#include + +#include "framework/operator.h" +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +template +class FlattenKernel + : public framework::OpKernelBase> { + public: + void Compute(const FlattenParam& param) const; + bool Init(FlattenParam* param); +}; +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/kernel/shape_kernel.h b/src/operators/kernel/shape_kernel.h new file mode 100644 index 0000000000000000000000000000000000000000..7caf3e427a4f3b469265248708a3090c52d1ca91 --- /dev/null +++ b/src/operators/kernel/shape_kernel.h @@ -0,0 +1,37 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef SHAPE_OP + +#pragma once + +#include + +#include "framework/operator.h" +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +template +class ShapeKernel + : public framework::OpKernelBase> { + public: + void Compute(const ShapeParam& param) const; + bool Init(ShapeParam* param); +}; +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/kernel/split_kernel.h b/src/operators/kernel/split_kernel.h new file mode 100644 index 0000000000000000000000000000000000000000..03a418de59606e42684c67ca3053fa8e39b07940 --- /dev/null +++ b/src/operators/kernel/split_kernel.h @@ -0,0 +1,37 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef SPLIT_OP + +#pragma once + +#include + +#include "framework/operator.h" +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +template +class SplitKernel + : public framework::OpKernelBase> { + public: + void Compute(const SplitParam& param) const; + bool Init(SplitParam* param); +}; +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/src/operators/op_param.h b/src/operators/op_param.h index 6142d9b584d868db6cf9f55c9f6f50f1317a98da..4f1fc897252de0578fca587da0d1529e604bfae8 100644 --- a/src/operators/op_param.h +++ b/src/operators/op_param.h @@ -91,6 +91,11 @@ class OpParam { static T *InputXFrom(const VariableNameMap &inputs, const Scope &scope) { return GetVarValue("X", inputs, scope); } + template + static T *InputOutSizeFrom(const VariableNameMap &inputs, + const Scope &scope) { + return GetVarValue("OutSize", inputs, scope); + } template static T *InputWFrom(const VariableNameMap &inputs, const Scope &scope) { @@ -2257,5 +2262,92 @@ class GruParam : public OpParam { }; #endif +#ifdef FLATTEN_OP +template +class FlattenParam : public OpParam { + typedef typename DtypeTensorTrait::gtype GType; + typedef typename DtypeTensorTrait::rtype RType; + + public: + FlattenParam(const VariableNameMap &inputs, const VariableNameMap &outputs, + const AttributeMap &attrs, const Scope &scope) { + input_x_ = InputXFrom(inputs, scope); + out_ = OutFrom(outputs, scope); + } + const RType *InputX() const { return input_x_; } + RType *Out() const { return out_; } + + private: + RType *input_x_; + RType *out_; +}; +#endif + +#ifdef SPLIT_OP +template +class SplitParam : public OpParam { + typedef typename DtypeTensorTrait::gtype GType; + typedef typename DtypeTensorTrait::rtype RType; + + public: + SplitParam(const VariableNameMap &inputs, const VariableNameMap &outputs, + const AttributeMap &attrs, const Scope &scope) { + input_x_ = InputXFrom(inputs, scope); + out_ = OutFrom(outputs, scope); + } + const RType *InputX() const { return input_x_; } + RType *Out() const { return out_; } + + private: + RType *input_x_; + RType *out_; +}; +#endif + +#ifdef BILINEAR_INTERP_OP +template +class BilinearInterpParam : public OpParam { + typedef typename DtypeTensorTrait::gtype GType; + typedef typename DtypeTensorTrait::rtype RType; + + public: + BilinearInterpParam(const VariableNameMap &inputs, + const VariableNameMap &outputs, const AttributeMap &attrs, + const Scope &scope) { + input_x_ = InputXFrom(inputs, scope); + input_outsize_ = InputOutSizeFrom(inputs, scope); + out_ = OutFrom(outputs, scope); + } + const RType *InputX() const { return input_x_; } + RType *Out() const { return out_; } + + private: + RType *input_x_; + RType *input_outsize_; + RType *out_; +}; +#endif + +#ifdef SHAPE_OP +template +class ShapeParam : public OpParam { + typedef typename DtypeTensorTrait::gtype GType; + typedef typename DtypeTensorTrait::rtype RType; + + public: + ShapeParam(const VariableNameMap &inputs, const VariableNameMap &outputs, + const AttributeMap &attrs, const Scope &scope) { + input_ = InputFrom(inputs, scope); + out_ = OutFrom(outputs, scope); + } + const RType *InputX() const { return input_; } + RType *Out() const { return out_; } + + private: + RType *input_; + RType *out_; +}; +#endif + } // namespace operators } // namespace paddle_mobile diff --git a/src/operators/shape_op.cpp b/src/operators/shape_op.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ed91fd5d663ebb734051e3636aa5f95e3623e4d9 --- /dev/null +++ b/src/operators/shape_op.cpp @@ -0,0 +1,38 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef SHAPE_OP + +#include "operators/shape_op.h" + +namespace paddle_mobile { +namespace operators { +template +void ShapeOp::InferShape() const { + this->param_.Out()->Resize(this->param_.InputX()->dims()); +} + +} // namespace operators +} // namespace paddle_mobile + +namespace ops = paddle_mobile::operators; +#ifdef PADDLE_MOBILE_CPU +REGISTER_OPERATOR_CPU(shape, ops::ShapeOp); +#endif +#ifdef PADDLE_MOBILE_MALI_GPU +#endif +#ifdef PADDLE_MOBILE_FPGA +#endif + +#endif diff --git a/src/operators/shape_op.h b/src/operators/shape_op.h new file mode 100644 index 0000000000000000000000000000000000000000..2f88c807d3c331f83cf87e6c77a65fa5d90a9f4e --- /dev/null +++ b/src/operators/shape_op.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef SHAPE_OP + +#pragma once + +#include + +#include "framework/operator.h" +#include "operators/kernel/shape_kernel.h" +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +using paddle_mobile::framework::Tensor; + +template +class ShapeOp : public framework::OperatorWithKernel< + DeviceType, ShapeParam, + operators::ShapeKernel> { + public: + ShapeOp(const std::string &type, const VariableNameMap &inputs, + const VariableNameMap &outputs, const framework::AttributeMap &attrs, + std::shared_ptr scope) + : framework::OperatorWithKernel, + operators::ShapeKernel>( + type, inputs, outputs, attrs, scope) {} + + using framework::OperatorWithKernel< + DeviceType, ShapeParam, + operators::ShapeKernel>::OperatorWithKernel; + void InferShape() const override; +}; + +} // namespace operators +} // namespace paddle_mobile + +#ifdef PADDLE_MOBILE_CPU +USE_OP_CPU(shape); +#endif +#ifdef PADDLE_MOBILE_MALI_GPU +#endif +#ifdef PADDLE_MOBILE_FPGA +#endif + +#endif diff --git a/src/operators/split_op.cpp b/src/operators/split_op.cpp new file mode 100644 index 0000000000000000000000000000000000000000..df4c2b276cfd90fcf6fe3d29d4f80ae667ee17e1 --- /dev/null +++ b/src/operators/split_op.cpp @@ -0,0 +1,38 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef SPLIT_OP + +#include "operators/split_op.h" + +namespace paddle_mobile { +namespace operators { +template +void SplitOp::InferShape() const { + this->param_.Out()->Resize(this->param_.InputX()->dims()); +} + +} // namespace operators +} // namespace paddle_mobile + +namespace ops = paddle_mobile::operators; +#ifdef PADDLE_MOBILE_CPU +REGISTER_OPERATOR_CPU(split, ops::SplitOp); +#endif +#ifdef PADDLE_MOBILE_MALI_GPU +#endif +#ifdef PADDLE_MOBILE_FPGA +#endif + +#endif diff --git a/src/operators/split_op.h b/src/operators/split_op.h new file mode 100644 index 0000000000000000000000000000000000000000..278b66d76cb5ed6cc02588602c64897260190bd1 --- /dev/null +++ b/src/operators/split_op.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef SPLIT_OP + +#pragma once + +#include + +#include "framework/operator.h" +#include "operators/kernel/split_kernel.h" +#include "operators/op_param.h" + +namespace paddle_mobile { +namespace operators { + +using paddle_mobile::framework::Tensor; + +template +class SplitOp : public framework::OperatorWithKernel< + DeviceType, SplitParam, + operators::SplitKernel> { + public: + SplitOp(const std::string &type, const VariableNameMap &inputs, + const VariableNameMap &outputs, const framework::AttributeMap &attrs, + std::shared_ptr scope) + : framework::OperatorWithKernel, + operators::SplitKernel>( + type, inputs, outputs, attrs, scope) {} + + using framework::OperatorWithKernel< + DeviceType, SplitParam, + operators::SplitKernel>::OperatorWithKernel; + void InferShape() const override; +}; + +} // namespace operators +} // namespace paddle_mobile + +#ifdef PADDLE_MOBILE_CPU +USE_OP_CPU(split); +#endif +#ifdef PADDLE_MOBILE_MALI_GPU +#endif +#ifdef PADDLE_MOBILE_FPGA +#endif + +#endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cf61a754ad6be3994307512004b8158e9c729da2..d9dd2634770fbcfce22f1c35790b0b81ac4fa346 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -208,6 +208,7 @@ else () target_link_libraries(test-gru-op paddle-mobile) # gen test + ADD_EXECUTABLE(test-inceptionv4 net/test_inceptionv4.cpp test_helper.h test_include.h executor_for_test.h) target_link_libraries(test-inceptionv4 paddle-mobile) @@ -215,6 +216,14 @@ else () ADD_EXECUTABLE(test-alexnet net/test_alexnet.cpp test_helper.h test_include.h executor_for_test.h) target_link_libraries(test-alexnet paddle-mobile) + ADD_EXECUTABLE(test-googlenetv1 net/test_googlenetv1_combine.cpp test_helper.h test_include.h) + target_link_libraries(test-googlenetv1 paddle-mobile) + + # gen test + ADD_EXECUTABLE(test-fssd net/test_mobilenet_025_fssd.cpp test_helper.h test_include.h) + target_link_libraries(test-fssd paddle-mobile) + + #add_library(test-lib-size SHARED common/test_lib_size.h common/test_lib_size.cpp) diff --git a/test/net/test_googlenetv1_combine.cpp b/test/net/test_googlenetv1_combine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9aab25afd2aa6ece4e6b99bbd368b8a5be2e3106 --- /dev/null +++ b/test/net/test_googlenetv1_combine.cpp @@ -0,0 +1,60 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include +#include "../test_helper.h" +#include "../test_include.h" + +int main() { + paddle_mobile::PaddleMobile paddle_mobile; + paddle_mobile.SetThreadNum(4); + auto time1 = time(); + if (paddle_mobile.Load(std::string(g_googlenetv1_combined) + "/model", + std::string(g_googlenetv1_combined) + "/params", + false)) { + auto time2 = time(); + std::cout << "load cost :" << time_diff(time1, time1) << "ms" << std::endl; + + std::vector input; + std::vector dims{1, 3, 160, 160}; + GetInput(g_img, &input, dims); + + for (int i = 0; i < input.size(); i += 1000) { + std::cout << input[i] << std::endl; + } + // auto vec_result = paddle_mobile.Predict(input, dims); + // std::vector::iterator biggest = + // std::max_element(std::begin(vec_result), std::end(vec_result)); + // std::cout << " Max element is " << *biggest << " at position " + // << std::distance(std::begin(vec_result), biggest) << + // std::endl; + + // // 预热十次 + // for (int i = 0; i < 1; ++i) { + // auto vec_result = paddle_mobile.Predict(input, dims); + // } + auto time3 = time(); + + auto vec_result = paddle_mobile.Predict(input, dims); + + for (int j = 0; j < vec_result.size(); ++j) { + std::cout << j << " : " << vec_result[j] << std::endl; + } + auto time4 = time(); + std::cout << "predict cost :" << time_diff(time3, time4) / 1 << "ms" + << std::endl; + } + + return 0; +} diff --git a/test/net/test_mobilenet_025_fssd.cpp b/test/net/test_mobilenet_025_fssd.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c1236d5bd6e91f17d7ded9b1709d52b9c3784aa6 --- /dev/null +++ b/test/net/test_mobilenet_025_fssd.cpp @@ -0,0 +1,50 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include +#include "../test_helper.h" +#include "../test_include.h" + +int main() { + paddle_mobile::PaddleMobile paddle_mobile; + paddle_mobile.SetThreadNum(4); + // ../../../test/models/googlenet + // ../../../test/models/mobilenet + auto time1 = time(); + if (paddle_mobile.Load(std::string(g_fluid_fssd_new) + "/model", + std::string(g_fluid_fssd_new) + "/params", false)) { + auto time2 = time(); + std::cout << "load cost :" << time_diff(time1, time1) << "ms" << std::endl; + + std::vector dims{1, 3, 160, 160}; + Tensor input_tensor; + SetupTensor(&input_tensor, {1, 3, 160, 160}, static_cast(0), + static_cast(1)); + + std::vector input(input_tensor.data(), + input_tensor.data() + input_tensor.numel()); + // 预热十次 + for (int i = 0; i < 10; ++i) { + paddle_mobile.Predict(input, dims); + } + auto time3 = time(); + for (int i = 0; i < 10; ++i) { + paddle_mobile.Predict(input, dims); + } + auto time4 = time(); + std::cout << "predict cost :" << time_diff(time3, time4) / 10 << "ms" + << std::endl; + } + return 0; +} diff --git a/test/test_helper.h b/test/test_helper.h index e93025a702ef2ece2c589c42ff05cef720d7e8dc..7581405c3d9f14e7e997e73be91cb624ad6d9798 100644 --- a/test/test_helper.h +++ b/test/test_helper.h @@ -29,6 +29,7 @@ static const char *g_mobilenet_ssd = "../models/mobilenet+ssd"; static const char *g_genet_combine = "../models/enet"; static const char *g_mobilenet_ssd_gesture = "../models/mobilenet+ssd_gesture"; static const char *g_mobilenet_combined = "../models/mobilenet_combine"; +static const char *g_googlenetv1_combined = "../models/googlenetv1_combine"; static const char *g_mobilenet_detect = "../models/mobilenet-detect"; static const char *g_squeezenet = "../models/squeezenet"; static const char *g_googlenet = "../models/googlenet"; @@ -40,11 +41,14 @@ static const char *g_resnet_50 = "../models/resnet_50"; static const char *g_resnet = "../models/resnet"; static const char *g_googlenet_combine = "../models/googlenet_combine"; static const char *g_yolo = "../models/yolo"; +static const char *g_fluid_fssd_new = "../models/fluid_fssd_new"; + static const char *g_test_image_1x3x224x224 = "../images/test_image_1x3x224x224_float"; static const char *g_test_image_1x3x224x224_banana = "../images/input_3x224x224_banana"; static const char *g_hand = "../images/hand_image"; +static const char *g_img = "../images/img.bin"; using paddle_mobile::framework::DDim; using paddle_mobile::framework::Tensor; diff --git a/tools/op.cmake b/tools/op.cmake index fa19f6eaac54823006778b5184ba0c683a90e7e2..3f27f7fc4ae0d00394b9df63c214b30f98cdd31b 100644 --- a/tools/op.cmake +++ b/tools/op.cmake @@ -165,6 +165,10 @@ if(NOT FOUND_MATCH) set(LOOKUP_OP ON) set(GRU_OP ON) set(CRF_OP ON) + set(BILINEAR_INTERP_OP ON) + set(SPLIT_OP ON) + set(FLATTEN_OP ON) + set(SHAPE_OP ON) endif() # option(BATCHNORM_OP "" ON) @@ -316,3 +320,20 @@ endif() if (CRF_OP) add_definitions(-DCRF_OP) endif() + + +if (FLATTEN_OP) + add_definitions(-DFLATTEN_OP) +endif() + +if (SPLIT_OP) + add_definitions(-DSPLIT_OP) +endif() + +if (BILINEAR_INTERP_OP) + add_definitions(-DBILINEAR_INTERP_OP) +endif() + +if (SHAPE_OP) + add_definitions(-DSHAPE_OP) +endif() \ No newline at end of file