reader_op.h 2.0 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
// 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.
W
serving  
wangguibao 已提交
14

W
wangguibao 已提交
15 16 17
#pragma once
#include <string>
#include <vector>
W
wangguibao 已提交
18
#include "demo-serving/image_class.pb.h"
W
wangguibao 已提交
19
#include "predictor/builtin_format.pb.h"
W
wangguibao 已提交
20 21 22 23
#include "predictor/common/inner_common.h"
#include "predictor/framework/channel.h"
#include "predictor/framework/op_repository.h"
#include "predictor/op/op.h"
W
serving  
wangguibao 已提交
24 25 26 27

// opencv
#include "opencv/cv.h"
#include "opencv/cv.hpp"
W
wangguibao 已提交
28 29
#include "opencv/cxcore.h"
#include "opencv/highgui.h"
W
serving  
wangguibao 已提交
30

W
wangguibao 已提交
31
#ifdef BCLOUD
W
Wang Guibao 已提交
32 33 34
#ifdef WITH_GPU
#include "paddle/paddle_inference_api.h"
#else
W
wangguibao 已提交
35
#include "paddle/fluid/inference/api/paddle_inference_api.h"
W
Wang Guibao 已提交
36
#endif
W
wangguibao 已提交
37
#else
W
wangguibao 已提交
38
#include "paddle_inference_api.h"  // NOLINT
W
wangguibao 已提交
39
#endif
W
serving  
wangguibao 已提交
40 41 42 43 44 45

namespace baidu {
namespace paddle_serving {
namespace serving {

struct ReaderOutput {
W
wangguibao 已提交
46
  std::vector<paddle::PaddleTensor> tensors;
W
serving  
wangguibao 已提交
47

W
wangguibao 已提交
48 49 50 51
  void Clear() {
    size_t tensor_count = tensors.size();
    for (size_t ti = 0; ti < tensor_count; ++ti) {
      tensors[ti].shape.clear();
W
serving  
wangguibao 已提交
52
    }
W
wangguibao 已提交
53 54 55 56
    tensors.clear();
  }

  std::string ShortDebugString() const { return "Not implemented!"; }
W
serving  
wangguibao 已提交
57 58
};

W
wangguibao 已提交
59 60 61 62
class ReaderOp
    : public baidu::paddle_serving::predictor::OpWithChannel<ReaderOutput> {
 public:
  typedef std::vector<paddle::PaddleTensor> TensorVector;
W
serving  
wangguibao 已提交
63

W
wangguibao 已提交
64
  DECLARE_OP(ReaderOp);
W
serving  
wangguibao 已提交
65

W
wangguibao 已提交
66
  int inference();
W
serving  
wangguibao 已提交
67

W
wangguibao 已提交
68 69 70 71
 private:
  cv::Mat _image_8u_tmp;
  cv::Mat _image_8u_rgb;
  std::vector<char> _image_vec_tmp;
W
serving  
wangguibao 已提交
72 73
};

W
wangguibao 已提交
74 75 76
}  // namespace serving
}  // namespace paddle_serving
}  // namespace baidu