test_prelu_op.cpp 1.8 KB
Newer Older
T
Tian 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* 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 "../executor_for_test.h"
#include "../test_include.h"
#include "operators/prelu_op.h"

int main() {
I
itminner 已提交
20 21 22 23
  paddle_mobile::Loader<paddle_mobile::CPU> loader;
  auto program = loader.Load(g_resnet);
  PADDLE_MOBILE_ENFORCE(program.originProgram != nullptr,
                        "program file read fail");
T
Tian 已提交
24

I
itminner 已提交
25 26 27
  Executor4Test<paddle_mobile::CPU,
                paddle_mobile::operators::PReluOp<paddle_mobile::CPU, float>>
      executor(program, "prelu");
T
Tian 已提交
28

I
itminner 已提交
29 30
  // 1. input_tensors;
  vector<Tensor> input_tensors;
T
Tian 已提交
31

I
itminner 已提交
32 33 34
  Tensor input1;
  auto input1_data = CreateInput<float>(&input1, {1, 2, 3, 4}, -1, 1);
  input_tensors.push_back(input1);
T
Tian 已提交
35

I
itminner 已提交
36 37 38 39
  // 2. input_names
  vector<string> input_names({
      "batch_norm_0.tmp_2",
  });
T
Tian 已提交
40

I
itminner 已提交
41 42
  // 3. output_names
  vector<string> output_names({"batch_norm_0.tmp_3"});
T
Tian 已提交
43

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

I
itminner 已提交
49 50
  auto output = executor.Predict<LoDTensor>(input_tensors, input_names,
                                            output_names, out_ddims);
T
Tian 已提交
51

I
itminner 已提交
52
  auto output0_data = output[0]->data<float>();
T
Tian 已提交
53

I
itminner 已提交
54 55 56 57
  for (int j = 0; j < output[0]->numel(); ++j) {
    DLOG << " value of output: " << output0_data[j];
  }
  return 0;
T
Tian 已提交
58
}