test_rfcn.cpp 1.9 KB
Newer Older
Z
zhangyang0701 已提交
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
/* 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 <iostream>
#include "../test_helper.h"
#include "../test_include.h"

#ifdef PADDLE_MOBILE_FPGA_V1
#include "fpga/V1/api.h"
#endif
#ifdef PADDLE_MOBILE_FPGA_V2
#include "fpga/V2/api.h"
#endif

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
void readStream(std::string filename, uint8_t *buf) {
  std::ifstream in;
  in.open(filename, std::ios::in);
  if (!in.is_open()) {
    std::cout << "open File Failed." << std::endl;
    return;
  }
  int i = 0;
  while (!in.eof()) {
    in >> buf[i];
    i++;
  }
  in.close();
}

static const char *g_rfcn_combine = "../models/rfcn";
42
static const char *g_image_src_float = "../models/rfcn/data.bin";
Z
zhangyang0701 已提交
43 44 45
int main() {
  paddle_mobile::fpga::open_device();
  paddle_mobile::PaddleMobile<paddle_mobile::FPGA> paddle_mobile;
46 47 48 49 50 51 52 53 54

  if (paddle_mobile.Load(std::string(g_rfcn_combine) + "/model",
                         std::string(g_rfcn_combine) + "/params", true, false,
                         1, true)) {
    float img_info[3] = {768, 1536, 768.0f / 960.0f};
    auto img = fpga::fpga_malloc(768 * 1536 * 3 * sizeof(float));
    readStream(g_image_src_float, reinterpret_cast<uint8_t *>(img));
    std::vector<void *> v(3, nullptr);
    paddle_mobile.FeedData({img_info, img});
Z
zhangyang0701 已提交
55
    paddle_mobile.Predict_To(-1);
56 57
    paddle_mobile.GetResults(&v);
    DLOG << "Computation done";
58
    fpga::fpga_free(img);
Z
zhangyang0701 已提交
59 60 61 62
  }

  return 0;
}