From d922996cef07bf03bcc02da56db598f06bc88d7f Mon Sep 17 00:00:00 2001 From: xiebaiyuan Date: Wed, 26 Sep 2018 16:56:23 +0800 Subject: [PATCH] add_yolo_combined unit test --- test/CMakeLists.txt | 7 ++++ test/net/test_yolo_combined.cpp | 60 +++++++++++++++++++++++++++++++++ test/test_helper.h | 3 ++ 3 files changed, 70 insertions(+) create mode 100644 test/net/test_yolo_combined.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ef03205ae5..44da835e7e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,6 +18,9 @@ elseif ("yolo" IN_LIST NET) # 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_yolo_combined net/test_yolo_combined.cpp test_helper.h test_include.h executor_for_test.h) + target_link_libraries(test_yolo_combined paddle-mobile) elseif ("squeezenet" IN_LIST NET) # gen test ADD_EXECUTABLE(test-squeezenet net/test_squeezenet.cpp test_helper.h test_include.h executor_for_test.h) @@ -74,6 +77,10 @@ else () 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_yolo_combined net/test_yolo_combined.cpp test_helper.h test_include.h executor_for_test.h) + target_link_libraries(test_yolo_combined 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) diff --git a/test/net/test_yolo_combined.cpp b/test/net/test_yolo_combined.cpp new file mode 100644 index 0000000000..88b889daa9 --- /dev/null +++ b/test/net/test_yolo_combined.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); + // ../../../test/models/googlenet + // ../../../test/models/mobilenet + auto time1 = time(); + + if (paddle_mobile.Load(std::string(g_yolo_combined) + "/model", + std::string(g_yolo_combined) + "/params", true)) { + auto time2 = time(); + std::cout << "load cost :" << time_diff(time1, time1) << "ms" << std::endl; + + std::vector dims{1, 3, 416, 416}; + std::vector input; + + GetInput(g_test_image_desktop_1_3_416_416_nchw_float, &input, dims); + std::cout << "input.size(): " << input.size() << std::endl; + for (int j = 0; j < 100; ++j) { + std::cout << j << " : " << input[j] << std::endl; + } + // // 预热十次 + // for (int i = 0; i < 10; ++i) { + // paddle_mobile.Predict(input, dims); + // } + auto time3 = time(); + const vector vector_out = paddle_mobile.Predict(input, dims); + std::cout << "--------------------------------------------" << std::endl; + + for (float i : vector_out) { + std::cout << i << std::endl; + } + + std::cout << "--------------------------------------------" << std::endl; + + std::cout << "load cost :" << time_diff(time1, time1) << "ms" << std::endl; + + 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 a6898b2cc8..ecbc251a81 100644 --- a/test/test_helper.h +++ b/test/test_helper.h @@ -41,12 +41,15 @@ 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_yolo_combined = "../models/yolo_combined"; 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_test_image_desktop_1_3_416_416_nchw_float = + "../images/in_put_1_3_416_416_2"; static const char *g_hand = "../images/hand_image"; static const char *g_imgfssd_ar = "../images/test_image_ssd_ar"; static const char *g_imgfssd_ar1 = "../images/003_0001.txt"; -- GitLab