test_lrn_op.cpp 2.5 KB
Newer Older
E
eclipsess 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* 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. */

E
eclipsess 已提交
15
#include "../executor_for_test.h"
E
eclipsess 已提交
16 17 18
#include "../test_include.h"
#include "operators/lrn_op.h"

E
eclipsess 已提交
19 20 21 22 23
int main() {
  paddle_mobile::Loader<paddle_mobile::CPU> loader;
  auto program = loader.Load(g_googlenet);
  PADDLE_MOBILE_ENFORCE(program.originProgram != nullptr,
                        "program file read fail");
24

E
eclipsess 已提交
25 26 27
  Executor4Test<paddle_mobile::CPU,
                paddle_mobile::operators::LrnOp<paddle_mobile::CPU, float>>
      executor(program, "lrn");
28

E
eclipsess 已提交
29 30
  // 1. input_tensors;
  vector<Tensor> input_tensors;
31

E
eclipsess 已提交
32 33 34
  Tensor input1;
  auto input1_data = CreateInput<float>(&input1, {3, 4, 2, 2}, 0, 1);
  input_tensors.push_back(input1);
E
eclipsess 已提交
35

E
eclipsess 已提交
36 37 38 39
  // 2. input_names
  vector<string> input_names({
      "pool2d_0.tmp_0",
  });
E
eclipsess 已提交
40

E
eclipsess 已提交
41 42
  // 3. output_names
  vector<string> output_names({"pool1_norm1.tmp_1"});
43

E
eclipsess 已提交
44 45 46 47
  // 4. out_dims;
  vector<DDim> out_ddims;
  auto out_ddim = paddle_mobile::framework::make_ddim({3, 4, 2, 2});
  out_ddims.push_back(out_ddim);
48

L
liuruilong 已提交
49
  auto output = executor.Predict<LoDTensor>(input_tensors, input_names,
E
eclipsess 已提交
50
                                            output_names, out_ddims);
51

E
eclipsess 已提交
52
  auto output0_data = output[0]->data<float>();
53 54 55 56 57 58

  DLOG << " LrnOp input: ";
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
      for (int c = 0; c < 2; c++) {
        for (int d = 0; d < 2; d++) {
E
eclipsess 已提交
59
          DLOGF("%f ", input1_data[i * 16 + j * 4 + c * 2 + d]);
E
eclipsess 已提交
60 61
        }
        DLOGF("\n");
62 63
      }
      DLOGF("\n");
E
eclipsess 已提交
64
    }
65 66 67 68 69 70 71
    DLOGF("\n");
  }
  DLOG << " LrnOp output: ";
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
      for (int c = 0; c < 2; c++) {
        for (int d = 0; d < 2; d++) {
E
eclipsess 已提交
72
          DLOGF("%f ", output0_data[i * 16 + j * 4 + c * 2 + d]);
E
eclipsess 已提交
73 74
        }
        DLOGF("\n");
75 76
      }
      DLOGF("\n");
E
eclipsess 已提交
77
    }
78 79
    DLOGF("\n");
  }
E
eclipsess 已提交
80 81 82
  DLOG << input1_data[0] << " / ((1 + 0.00002 * ( " << input1_data[0] << "^2 + "
       << input1_data[4] << "^2 + " << input1_data[8] << "^2 ))^0.75) = ";
  DLOG << output0_data[0];
83
  return 0;
E
eclipsess 已提交
84
}