reader_op.h 1.9 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 18
#pragma once
#include <string>
#include <vector>
#include "predictor/builtin_format.pb.h"
W
wangguibao 已提交
19 20 21 22
#include "predictor/common/inner_common.h"
#include "predictor/framework/channel.h"
#include "predictor/framework/op_repository.h"
#include "predictor/op/op.h"
W
wangguibao 已提交
23
#include "serving/image_class.pb.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 32 33
#ifdef BCLOUD
#include "paddle/fluid/inference/api/paddle_inference_api.h"
#else
W
serving  
wangguibao 已提交
34
#include "paddle/fluid/inference/paddle_inference_api.h"
W
wangguibao 已提交
35
#endif
W
serving  
wangguibao 已提交
36 37 38 39 40 41

namespace baidu {
namespace paddle_serving {
namespace serving {

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

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

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

W
wangguibao 已提交
55 56 57 58
class ReaderOp
    : public baidu::paddle_serving::predictor::OpWithChannel<ReaderOutput> {
 public:
  typedef std::vector<paddle::PaddleTensor> TensorVector;
W
serving  
wangguibao 已提交
59

W
wangguibao 已提交
60
  DECLARE_OP(ReaderOp);
W
serving  
wangguibao 已提交
61

W
wangguibao 已提交
62
  int inference();
W
serving  
wangguibao 已提交
63

W
wangguibao 已提交
64 65 66 67
 private:
  cv::Mat _image_8u_tmp;
  cv::Mat _image_8u_rgb;
  std::vector<char> _image_vec_tmp;
W
serving  
wangguibao 已提交
68 69
};

W
wangguibao 已提交
70 71 72
}  // namespace serving
}  // namespace paddle_serving
}  // namespace baidu