test_im2sequence_op.cpp 1.9 KB
Newer Older
Y
yaokun01 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/* 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/im2sequence_op.h"

int main() {
  paddle_mobile::Loader<paddle_mobile::CPU> loader;
  auto program = loader.Load(g_ocr_recg);
  PADDLE_MOBILE_ENFORCE(program.originProgram != nullptr,
                        "program file read fail");

  Executor4Test<paddle_mobile::CPU,
                paddle_mobile::operators::ReluOp<paddle_mobile::CPU, float>>
      executor(program, "im2sequence");

  // 1. input_tensors;
  vector<Tensor> input_tensors;

  Tensor input1;
  auto input1_data = CreateInput<float>(&input1, {2, 2, 3, 3}, -1, 1);
  input_tensors.push_back(input1);

  // 2. input_names
  vector<string> input_names({
      "conv2d_19.tmp_1",
  });

  // 3. output_names
  vector<string> output_names({"im2sequence_0.tmp_0"});

  // 4. out_dims;
  vector<DDim> out_ddims;
  auto out_ddim = paddle_mobile::framework::make_ddim({8, 9});
  out_ddims.push_back(out_ddim);

  auto output = executor.Predict<LoDTensor>(input_tensors, input_names,
                                            output_names, out_ddims);

  auto output0_data = output[0]->data<float>();

  for (int j = 0; j < input_tensors[0].numel(); ++j) {
    DLOG << " value of input: " << input1_data[j];
  }

  for (int j = 0; j < output[0]->numel(); ++j) {
    DLOG << " value of output: " << output0_data[j];
  }
  return 0;
}