diff --git a/src/common/types.h b/src/common/types.h index b25ae329931a79e9dd73b4a213a86aacc2464787..ca9e64cc60f067e952dd481ce978b7b1a5bc5f13 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -95,17 +95,23 @@ static const std::string G_OP_TYPE_FETCH = "fetch"; static std::unordered_map< std::string, std::pair, std::vector>> - op_input_output_key = {{G_OP_TYPE_CONV, {{"Input"}, {"Output"}}}, - {G_OP_TYPE_RELU, {{"X"}, {"Out"}}}, - {G_OP_TYPE_SOFTMAX, {{"X"}, {"Out"}}}, - {G_OP_TYPE_MUL, {{"X"}, {"Out"}}}, - {G_OP_TYPE_ELEMENTWISE_ADD, {{"X", "Y"}, {"Out"}}}, - {G_OP_TYPE_POOL2D, {{"X"}, {"Out"}}}, - {G_OP_TYPE_BATCHNORM, {{"X"}, {"Y"}}}, - {G_OP_TYPE_LRN, {{"X"}, {"Out"}}}, - {G_OP_TYPE_CONCAT, {{"X"}, {"Out"}}}, - {G_OP_TYPE_SPLIT, {{"X"}, {"Out"}}}, - {G_OP_TYPE_FEED, {{"X"}, {"Out"}}}, - {G_OP_TYPE_FETCH, {{"X"}, {"Out"}}}}; - + op_input_output_key = { + {G_OP_TYPE_CONV, {{"Input"}, {"Output"}}}, + {G_OP_TYPE_RELU, {{"X"}, {"Out"}}}, + {G_OP_TYPE_SOFTMAX, {{"X"}, {"Out"}}}, + {G_OP_TYPE_MUL, {{"X"}, {"Out"}}}, + {G_OP_TYPE_ELEMENTWISE_ADD, {{"X", "Y"}, {"Out"}}}, + {G_OP_TYPE_POOL2D, {{"X"}, {"Out"}}}, + {G_OP_TYPE_BATCHNORM, {{"X"}, {"Y"}}}, + {G_OP_TYPE_LRN, {{"X"}, {"Out"}}}, + {G_OP_TYPE_CONCAT, {{"X"}, {"Out"}}}, + {G_OP_TYPE_SPLIT, {{"X"}, {"Out"}}}, + {G_OP_TYPE_FEED, {{"X"}, {"Out"}}}, + {G_OP_TYPE_FETCH, {{"X"}, {"Out"}}}, + {G_OP_TYPE_TRANSPOSE, {{"X"}, {"Out"}}}, + {G_OP_TYPE_BOX_CODER, + {{"PriorBox", "PriorBoxVar", "TargetBox"}, {"OutputBox"}}}, + {G_OP_TYPE_PRIOR_BOX, {{"Image", "Input"}, {"Boxes", "Variances"}}}, + {G_OP_TYPE_MULTICLASS_NMS, {{"BBoxes", "Scores"}, {"Out"}}}, + {G_OP_TYPE_RESHAPE, {{"X"}, {"Out"}}}}; } // namespace paddle_mobile diff --git a/src/framework/operator.h b/src/framework/operator.h index 8e5e55fb469d65212795d13bf17ec02de27c2db1..6194e5dcfff2c0320318d3e30e5c8204cd71a749 100644 --- a/src/framework/operator.h +++ b/src/framework/operator.h @@ -38,6 +38,7 @@ namespace paddle_mobile { namespace framework { using std::string; using std::vector; + template class OperatorBase : PaddleMobileObject { public: diff --git a/src/io.cpp b/src/io.cpp index 002e73b79648320c229786f8492f4c0e8b299d83..b8350a81118d8187552854f8ed7cab3a13dab8f6 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -220,7 +220,7 @@ const framework::Program Loader::Load( } } } - // originProgramDesc->Description("program: "); + originProgramDesc->Description("program: "); if (optimize) { framework::ProgramOptimize program_optimize; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2bb313342e21aac9dabced37039de8225c0a64ec..c71306281e3354cd1856ecaa7278266b031b665c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -84,10 +84,29 @@ target_link_libraries(test-gemm paddle-mobile) ADD_EXECUTABLE(test-enforce common/test_enforce.cpp) target_link_libraries(test-enforce paddle-mobile) +# gen test +ADD_EXECUTABLE(test-yolo net/test_yolo.cpp test_helper.h test_include.h executor_for_test.h) +target_link_libraries(test-yolo paddle-mobile) + # gen test ADD_EXECUTABLE(test-googlenet net/test_googlenet.cpp test_helper.h test_include.h executor_for_test.h) target_link_libraries(test-googlenet paddle-mobile) +# gen test +ADD_EXECUTABLE(test-mobilenet net/test_mobilenet.cpp test_helper.h test_include.h executor_for_test.h) +target_link_libraries(test-mobilenet paddle-mobile) + +# gen test +ADD_EXECUTABLE(test-resnet net/test_resnet.cpp test_helper.h test_include.h executor_for_test.h) +target_link_libraries(test-resnet paddle-mobile) +# gen test +ADD_EXECUTABLE(test-mobilenetssd net/test_mobilenet+ssd.cpp test_helper.h test_include.h executor_for_test.h) +target_link_libraries(test-mobilenetssd paddle-mobile) + +# gen test +ADD_EXECUTABLE(test-squeezenet net/test_squeezenet.cpp test_helper.h test_include.h executor_for_test.h) +target_link_libraries(test-squeezenet paddle-mobile) + # gen test ADD_EXECUTABLE(test-sigmoid operators/test_sigmoid_op.cpp test_include.h) target_link_libraries(test-sigmoid paddle-mobile) diff --git a/test/net/test_mobilenet+ssd.cpp b/test/net/test_mobilenet+ssd.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e9d92e7a51b9f7abe2c451df4073428bd2bd6d5f --- /dev/null +++ b/test/net/test_mobilenet+ssd.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. */ + +#include +#include "../test_helper.h" +#include "../test_include.h" + +int main() { + paddle_mobile::Loader loader; + auto time1 = time(); + auto program = loader.Load(g_mobilenet_ssd, false); + auto time2 = time(); + DLOG << "load cost :" << time_diff(time1, time1) << "ms"; + paddle_mobile::Executor executor(program, 1, false); + + std::vector dims{1, 3, 300, 300}; + Tensor input_tensor; + SetupTensor(&input_tensor, {1, 3, 300, 300}, static_cast(0), + static_cast(1)); + + std::vector input(input_tensor.data(), + input_tensor.data() + input_tensor.numel()); + auto time3 = time(); + executor.Predict(input, dims); + auto time4 = time(); + DLOG << "predict cost :" << time_diff(time3, time4) << "ms"; + return 0; +} diff --git a/test/net/test_mobilenet.cpp b/test/net/test_mobilenet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b5d925227e4ccf8925440ee36c3f9a6e02567f91 --- /dev/null +++ b/test/net/test_mobilenet.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. */ + +#include +#include "../test_helper.h" +#include "../test_include.h" + +int main() { + paddle_mobile::Loader loader; + auto time1 = time(); + auto program = loader.Load(g_mobilenet, false); + auto time2 = time(); + DLOG << "load cost :" << time_diff(time1, time1) << "ms"; + paddle_mobile::Executor executor(program, 1, false); + + std::vector dims{1, 3, 224, 224}; + Tensor input_tensor; + SetupTensor(&input_tensor, {1, 3, 224, 224}, static_cast(0), + static_cast(1)); + + std::vector input(input_tensor.data(), + input_tensor.data() + input_tensor.numel()); + auto time3 = time(); + executor.Predict(input, dims); + auto time4 = time(); + DLOG << "predict cost :" << time_diff(time3, time4) << "ms"; + return 0; +} diff --git a/test/net/test_resnet.cpp b/test/net/test_resnet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..55f4c5efef209c421fc550c1f17422acd64b11b9 --- /dev/null +++ b/test/net/test_resnet.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. */ + +#include +#include "../test_helper.h" +#include "../test_include.h" + +int main() { + paddle_mobile::Loader loader; + auto time1 = time(); + auto program = loader.Load(g_resnet, false); + auto time2 = time(); + DLOG << "load cost :" << time_diff(time1, time1) << "ms"; + paddle_mobile::Executor executor(program, 1, false); + + std::vector dims{1, 3, 32, 32}; + Tensor input_tensor; + SetupTensor(&input_tensor, {1, 3, 32, 32}, static_cast(0), + static_cast(1)); + + std::vector input(input_tensor.data(), + input_tensor.data() + input_tensor.numel()); + auto time3 = time(); + executor.Predict(input, dims); + auto time4 = time(); + DLOG << "predict cost :" << time_diff(time3, time4) << "ms"; + return 0; +} diff --git a/test/net/test_squeezenet.cpp b/test/net/test_squeezenet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..30460018fe8cc008e0031c1c713150745767fa28 --- /dev/null +++ b/test/net/test_squeezenet.cpp @@ -0,0 +1,41 @@ +/* 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::Loader loader; + // ../../../test/models/googlenet + // ../../../test/models/mobilenet + auto time1 = time(); + auto program = loader.Load(g_squeezenet, false); + auto time2 = time(); + DLOG << "load cost :" << time_diff(time1, time1) << "ms"; + paddle_mobile::Executor executor(program, 1, false); + + std::vector dims{1, 3, 227, 227}; + Tensor input_tensor; + SetupTensor(&input_tensor, {1, 3, 227, 227}, static_cast(0), + static_cast(1)); + + std::vector input(input_tensor.data(), + input_tensor.data() + input_tensor.numel()); + auto time3 = time(); + executor.Predict(input, dims); + auto time4 = time(); + DLOG << "predict cost :" << time_diff(time3, time4) << "ms"; + return 0; +} diff --git a/test/net/test_yolo.cpp b/test/net/test_yolo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c82443e23953def917826fe4ec3b2c484b588f59 --- /dev/null +++ b/test/net/test_yolo.cpp @@ -0,0 +1,41 @@ +/* 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::Loader loader; + // ../../../test/models/googlenet + // ../../../test/models/mobilenet + auto time1 = time(); + auto program = loader.Load(g_yolo, false); + auto time2 = time(); + DLOG << "load cost :" << time_diff(time1, time1) << "ms"; + paddle_mobile::Executor executor(program, 1, false); + + std::vector dims{1, 3, 227, 227}; + Tensor input_tensor; + SetupTensor(&input_tensor, {1, 3, 227, 227}, static_cast(0), + static_cast(1)); + + std::vector input(input_tensor.data(), + input_tensor.data() + input_tensor.numel()); + auto time3 = time(); + executor.Predict(input, dims); + auto time4 = time(); + DLOG << "predict cost :" << time_diff(time3, time4) << "ms"; + return 0; +} diff --git a/test/test_helper.h b/test/test_helper.h index dba4dec9bbc0a8066eef6c6dea9828dfb9954200..fc4ed6c91dc9b03c1f4dadfd8a4bc94efe3a724e 100644 --- a/test/test_helper.h +++ b/test/test_helper.h @@ -28,6 +28,7 @@ static const std::string g_mobilenet_ssd = "../models/mobilenet+ssd"; static const std::string g_squeezenet = "../models/squeezenet"; static const std::string g_resnet = "../models/image_classification_resnet.inference.model"; +static const std::string g_yolo = "../models/yolo"; static const std::string g_test_image_1x3x224x224 = "../images/test_image_1x3x224x224_float"; using paddle_mobile::framework::DDim;