diff --git a/paddle/fluid/lite/CMakeLists.txt b/paddle/fluid/lite/CMakeLists.txt index 9da0973c6dc15c442269e7603db4216a4c568d93..b35a72331d7e0323297495025ac1ea8ba5bde56b 100644 --- a/paddle/fluid/lite/CMakeLists.txt +++ b/paddle/fluid/lite/CMakeLists.txt @@ -204,4 +204,7 @@ if (WITH_TESTING) lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "resnet50.tar.gz") lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "inception_v4.tar.gz") endif() + if(NOT LITE_WITH_LIGHT_WEIGHT_FRAMEWORK) + lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "GoogleNet_inference.tar.gz") + endif() endif() diff --git a/paddle/fluid/lite/api/CMakeLists.txt b/paddle/fluid/lite/api/CMakeLists.txt index d4094b4dca894ab88546f6ef17bb2e9e2a417ddf..d3d8c4900f5adeb9b5d7f6c0eeb7a03bc519cd61 100644 --- a/paddle/fluid/lite/api/CMakeLists.txt +++ b/paddle/fluid/lite/api/CMakeLists.txt @@ -45,6 +45,11 @@ if(NOT LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND WITH_TESTING) ARGS --model_dir=${LITE_MODEL_DIR}/lite_naive_model --optimized_model=${LITE_MODEL_DIR}/lite_naive_model_opt SERIAL) add_dependencies(test_cxx_api_lite extern_lite_download_lite_naive_model_tar_gz) + lite_cc_test(test_googlenet_lite SRCS test_googlenet_lite.cc + DEPS cxx_api_lite mir_passes lite_api_test_helper + ${ops_lite} ${host_kernels} ${x86_kernels} + ARGS --model_dir=${LITE_MODEL_DIR}/googlenet) + add_dependencies(test_googlenet_lite extern_lite_download_GoogleNet_inference_tar_gz) endif() diff --git a/paddle/fluid/lite/api/test_googlenet_lite.cc b/paddle/fluid/lite/api/test_googlenet_lite.cc new file mode 100644 index 0000000000000000000000000000000000000000..16005be865f3a9c8e09d21b569f8d650f5b716e7 --- /dev/null +++ b/paddle/fluid/lite/api/test_googlenet_lite.cc @@ -0,0 +1,82 @@ +// Copyright (c) 2019 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. + +// Copyright (c) 2019 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 +#include +#include +#include +#include "paddle/fluid/lite/api/cxx_api.h" +#include "paddle/fluid/lite/api/lite_api_test_helper.h" +#include "paddle/fluid/lite/core/compatible_tensor.h" +#include "paddle/fluid/lite/core/mir/use_passes.h" +#include "paddle/fluid/lite/core/op_registry.h" +#include "paddle/fluid/lite/kernels/use_kernels.h" +#include "paddle/fluid/lite/operators/use_ops.h" + +// for googlenet +DEFINE_string(model_dir, "", ""); + +namespace paddle { +namespace lite { +#ifdef LITE_WITH_X86 +TEST(CXXApi, test_lite_googlenet) { + lite::Predictor predictor; + std::vector valid_places({Place{TARGET(kHost), PRECISION(kFloat)}, + Place{TARGET(kX86), PRECISION(kFloat)}}); + + // LOG(INFO)<<"FLAGS_eval_googlenet_dir:"<Resize(DDim(std::vector({1, 3, 224, 224}))); + auto* data = input_tensor->mutable_data(); + for (int i = 0; i < input_tensor->dims().production(); i++) { + data[i] = 1; + } + predictor.Run(); + + auto* out = predictor.GetOutput(0); + std::vector results( + {0.00034298553, 0.0008200012, 0.0005046297, 0.000839279, + 0.00052616704, 0.0003447803, 0.0010877076, 0.00081762316, + 0.0003941339, 0.0011430943, 0.0008892841, 0.00080191303, + 0.0004442384, 0.000658702, 0.0026721435, 0.0013686896, + 0.0005618166, 0.0006556497, 0.0006984528, 0.0014619455}); + for (size_t i = 0; i < results.size(); ++i) { + EXPECT_NEAR(out->data()[i * 51], results[i], 1e-5); + } + ASSERT_EQ(out->dims().size(), 2); + ASSERT_EQ(out->dims()[0], 1); + ASSERT_EQ(out->dims()[1], 1000); +} +#endif +} // namespace lite +} // namespace paddle diff --git a/paddle/fluid/lite/kernels/x86/concat_compute.cc b/paddle/fluid/lite/kernels/x86/concat_compute.cc index 4e1872951d74335a3bad97597a0104fe54f52d25..8976ed9675b0a6ae6361d65326ffb7e8a8fd0e0c 100644 --- a/paddle/fluid/lite/kernels/x86/concat_compute.cc +++ b/paddle/fluid/lite/kernels/x86/concat_compute.cc @@ -16,6 +16,6 @@ REGISTER_LITE_KERNEL(concat, kX86, kFloat, kNCHW, paddle::lite::kernels::x86::ConcatCompute, def) - .BindInput("X", {LiteType::GetTensorListTy(TARGET(kX86))}) + .BindInput("X", {LiteType::GetTensorTy(TARGET(kX86))}) .BindOutput("Out", {LiteType::GetTensorTy(TARGET(kX86))}) .Finalize(); diff --git a/paddle/fluid/lite/kernels/x86/pool_compute.cc b/paddle/fluid/lite/kernels/x86/pool_compute.cc index ee1bb9dbd5d57a82df6dfdda8997a39d1555d01b..7c188db3c73e00df685adbba4db0116a7dc8e591 100644 --- a/paddle/fluid/lite/kernels/x86/pool_compute.cc +++ b/paddle/fluid/lite/kernels/x86/pool_compute.cc @@ -16,6 +16,6 @@ REGISTER_LITE_KERNEL(pool2d, kX86, kFloat, kNCHW, paddle::lite::kernels::x86::PoolCompute, def) - .BindInput("x", {LiteType::GetTensorTy(TARGET(kX86))}) + .BindInput("X", {LiteType::GetTensorTy(TARGET(kX86))}) .BindOutput("Out", {LiteType::GetTensorTy(TARGET(kX86))}) .Finalize(); diff --git a/paddle/fluid/lite/kernels/x86/softmax_compute.h b/paddle/fluid/lite/kernels/x86/softmax_compute.h index 984a56965a822cf567e69a2c12523fefbc94a9d2..e51162095d938f1a0acc30478337916626777397 100644 --- a/paddle/fluid/lite/kernels/x86/softmax_compute.h +++ b/paddle/fluid/lite/kernels/x86/softmax_compute.h @@ -58,6 +58,7 @@ class SoftmaxCompute : public KernelLite { // auto& context = context_->As(); CHECK(param.output); CHECK(param.x); + param.output->mutable_data(); const int rank = param.x->dims().size(); const int axis = CanonicalAxis(param.axis, rank); int axis_dim = param.x->dims()[axis];