diff --git a/.gitignore b/.gitignore index a99cec2f60a9b587125ac172035ef6df56675324..d7243ae9ca5541c81c2ac101448ca70270731e7e 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,5 @@ paddle-mobile.cbp cmake-build-debug/ + +test/models/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7013d29ce543f14ef70d7c1021620b602bd91f95..22222421a8c9c0bdbff9431ad6dfcde1aeb81e6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,12 +46,4 @@ ADD_LIBRARY(paddle-mobile-static STATIC ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H}) target_link_libraries(paddle-mobile-static protobuf-lite openblas) #add_dependencies(paddle-mobile openblas_proj) -# gen test -ADD_EXECUTABLE(paddle-mobile-test test/main.cpp test/test_helper.h - test/elementwise_add_op_test.h test/test_include.h - test/mul_op_test.h) -target_link_libraries(paddle-mobile-test paddle-mobile) - -# gen test log -ADD_EXECUTABLE(test-log test/unit-test/test_log.cpp) -target_link_libraries(test-log paddle-mobile) +add_subdirectory(test) \ No newline at end of file diff --git a/src/framework/operator.h b/src/framework/operator.h index 45cb08724e658ae0977b7b63915ec50650711798..e4c3127e000e9abb803a4e85c93148e29aa7adb2 100644 --- a/src/framework/operator.h +++ b/src/framework/operator.h @@ -18,6 +18,8 @@ SOFTWARE. #pragma once +#include + #include "attribute.h" #include "block_desc.h" #include "common/type_define.h" @@ -29,10 +31,18 @@ SOFTWARE. #include "scope.h" #include "tensor.h" #include "variable.h" -#include namespace paddle_mobile { namespace framework { + static std::unordered_map> + op_input_output_key = { + {"conv2d", {"Input", "Output"}}, {"relu", {"X", "Out"}}, + {"softmax", {"X", "Out"}}, {"mul", {"X", "Out"}}, + {"elementwise_add", {"X", "Out"}}, {"pool2d", {"X", "Out"}}, + {"batch_norm", {"X", "Y"}}, {"lrn", {"X", "Out"}}, + {"concat", {"X", "Out"}}, + + }; template class OperatorBase : PaddleMobileObject { public: diff --git a/src/io.cpp b/src/io.cpp index c243681b25f440f9d7a6e673ff2254e13edebfdb..b40a2affc79599f3f75872dd741cf1a44e6bbf0c 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -17,7 +17,6 @@ SOFTWARE. ==============================================================================*/ #include -//#include #include "common/log.h" #include "framework/framework.pb.h" @@ -42,27 +41,26 @@ namespace paddle_mobile { template void Loader::LoadVar(framework::LoDTensor *tensor, const std::string &file_path) { - - LOG(kLOG_DEBUG) << " to load " << file_path; + // LOG(kLOG_DEBUG) << " to load " << file_path; // Log(kLOG_DEBUG) << "123"; std::ifstream is(file_path); std::streampos pos = is.tellg(); // save current position is.seekg(0, std::ios::end); - LOG(kLOG_DEBUG) << " file length = " << is.tellg(); + // LOG(kLOG_DEBUG) << " file length = " << is.tellg(); is.seekg(pos); // restore saved position // 1. version uint32_t version; is.read(reinterpret_cast(&version), sizeof(version)); - LOG(kLOG_INFO) << " version: " << version; + // LOG(kLOG_INFO) << " version: " << version; // 2 Lod information uint64_t lod_level; is.read(reinterpret_cast(&lod_level), sizeof(lod_level)); - LOG(kLOG_DEBUG) << " load level: " << lod_level; - LOG(kLOG_DEBUG) << " lod info: "; + // LOG(kLOG_DEBUG) << " load level: " << lod_level; + // LOG(kLOG_DEBUG) << " lod info: "; auto &lod = *tensor->mutable_lod(); lod.resize(lod_level); for (uint64_t i = 0; i < lod_level; ++i) { @@ -197,32 +195,26 @@ namespace paddle_mobile { #ifdef PADDLE_MOBILE_DEBUG for (int i = 0; i < program_desc_proto.blocks().size(); ++i) { framework::proto::BlockDesc block = program_desc_proto.blocks()[i]; - // std::cout << "block: " << block.idx() << std::endl; + LOG(kLOG_DEBUG) << "block: " << block.idx(); for (int j = 0; j < block.ops().size(); ++j) { framework::proto::OpDesc op = block.ops()[j]; - - // std::cout << " op: " << op.type() << std::endl; + LOG(kLOG_DEBUG1) << " op: " << op.type(); for (int m = 0; m < op.inputs_size(); ++m) { const framework::proto::OpDesc::Var &var = op.inputs(m); - // std::cout << " input parameter: " << - // var.parameter() << - // std::endl; + LOG(kLOG_DEBUG2) << " input parameter: " + << var.parameter(); for (int n = 0; n < var.arguments().size(); ++n) { - // std::cout << " argument - " << - // var.arguments()[n] << - // std::endl; + LOG(kLOG_DEBUG3) << " argument - " + << var.arguments()[n]; } } for (int y = 0; y < op.outputs_size(); ++y) { const framework::proto::OpDesc::Var &var = op.outputs(y); - // std::cout << " output parameter: " << - // var.parameter() << - // std::endl; + LOG(kLOG_DEBUG2) << " out parameter: " << var.parameter(); for (int z = 0; z < var.arguments().size(); ++z) { - // std::cout << " argument - " << - // var.arguments()[z] << - // std::endl; + LOG(kLOG_DEBUG3) << " argument - " + << var.arguments()[z]; } } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4a3227e902fa138ad95d58f5d6d2e058387ac5b7 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,16 @@ + +# gen test +ADD_EXECUTABLE(paddle-mobile-test main.cpp test_helper.h elementwise_add_op_test.h test_include.h mul_op_test.h) +target_link_libraries(paddle-mobile-test paddle-mobile) + +# gen test +ADD_EXECUTABLE(test-conv-op operators/test_cov_op.cpp test_helper.h test_include.h) +target_link_libraries(test-conv-op paddle-mobile) + +# gen test log +ADD_EXECUTABLE(test-log common/test_log.cpp) +target_link_libraries(test-log paddle-mobile) + +# gen test log +ADD_EXECUTABLE(test-load framework/test_load.cpp) +target_link_libraries(test-load paddle-mobile) \ No newline at end of file diff --git a/test/unit-test/test_log.cpp b/test/common/test_log.cpp similarity index 95% rename from test/unit-test/test_log.cpp rename to test/common/test_log.cpp index afedb9664453ae249e89d958d9d026499c888c2f..f362026951f4ff71d1c37fa656dea87494fe33f1 100644 --- a/test/unit-test/test_log.cpp +++ b/test/common/test_log.cpp @@ -19,18 +19,19 @@ SOFTWARE. #include "common/log.h" int main() { + DLOGF("DASJFDAFJ%d -- %f", 12345, 344.234); + + LOGF( paddle_mobile::kLOG_DEBUG, "DASJFDAFJ%d -- %f", 12345, 344.234); + LOG(paddle_mobile::kLOG_DEBUG) << "test debug" << " next log"; LOG(paddle_mobile::kLOG_DEBUG1) << "test debug1" << " next log"; - LOG(paddle_mobile::kLOG_DEBUG2) << "test debug2" << " next log"; - DLOG << "test DLOG"; - LOG(paddle_mobile::kLOG_ERROR) << " error occur !"; return 0; diff --git a/test/framework/test_load.cpp b/test/framework/test_load.cpp new file mode 100644 index 0000000000000000000000000000000000000000..35338fcebff68e88ea54632b25c261a41d5e2f25 --- /dev/null +++ b/test/framework/test_load.cpp @@ -0,0 +1,28 @@ +/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +==============================================================================*/ + +#include "io.h" + +int main() { + paddle_mobile::Loader loader; + + //../../../test/models/googlenet + //../../../test/models/mobilenet + auto program = loader.Load(std::string("../../../test/models/mobilenet")); + return 0; +} \ No newline at end of file diff --git a/test/main.cpp b/test/main.cpp index afb2f87845fb9c97c35f3954f08b27c72dba69f1..7af115f7ecffa4c89266908293ac04821f123792 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -17,9 +17,9 @@ SOFTWARE. ==============================================================================*/ #include "elementwise_add_op_test.h" -#include "mul_op_test.h" #include "framework/executor.h" #include "io.h" +#include "mul_op_test.h" #include "test_helper.h" // @@ -38,6 +38,7 @@ SOFTWARE. //} int main() { + std::string data_set = "cifar10"; // // if (data_set == "cifar10") { diff --git a/test/operators/test_cov_op.cpp b/test/operators/test_cov_op.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1902e44f632ca60c416d64c9ba00e5eca1ed94c6 --- /dev/null +++ b/test/operators/test_cov_op.cpp @@ -0,0 +1,64 @@ +/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +==============================================================================*/ + +#include "../test_helper.h" +#include "framework/executor.h" +#include "io.h" + +int main() { + + std::string data_set = "cifar10"; + // + // if (data_set == "cifar10") { + // SetupTensor(&input, {FLAGS_batch_size, 3, 32, 32}, + // static_cast(0), static_cast(1)); + // } else if (data_set == "imagenet") { + // SetupTensor(&input, {FLAGS_batch_size, 3, 224, 224}, + // static_cast(0), static_cast(1)); + // } else { + // LOG(FATAL) << "Only cifar10 or imagenet is supported."; + // } + + paddle_mobile::Loader loader; + auto program = loader.Load(std::string("../../../test/models/googlenet")); + + paddle_mobile::framework::Executor executor(program); + + paddle_mobile::framework::Tensor input; + SetupTensor(&input, {1, 3, 32, 32}, static_cast(0), + static_cast(1)); + float *input_ptr = input.data(); + for (int i = 0; i < input.numel(); ++i) { + // std::cout << input_ptr[i] << std::endl; + } + + // std::cout << "input: " << input.memory_size() << std::endl; + // std::cout << "input: " << input.numel() << std::endl; + + auto output = executor.predict(input); + + // std::cout << "output: " << output->memory_size() << std::endl; + // std::cout << "output: " << output->numel() << std::endl; + + // float* output_ptr = output->data(); + // for (int j = 0; j < output->numel(); ++j) { + // std::cout << " value of output: " << output_ptr[j] << std::endl; + // + + return 0; +}