reader_op.h 1.8 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 31 32 33 34 35 36 37

#include "paddle/fluid/inference/paddle_inference_api.h"

namespace baidu {
namespace paddle_serving {
namespace serving {

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

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

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

W
wangguibao 已提交
51 52 53 54
class ReaderOp
    : public baidu::paddle_serving::predictor::OpWithChannel<ReaderOutput> {
 public:
  typedef std::vector<paddle::PaddleTensor> TensorVector;
W
serving  
wangguibao 已提交
55

W
wangguibao 已提交
56
  DECLARE_OP(ReaderOp);
W
serving  
wangguibao 已提交
57

W
wangguibao 已提交
58
  int inference();
W
serving  
wangguibao 已提交
59

W
wangguibao 已提交
60 61 62 63
 private:
  cv::Mat _image_8u_tmp;
  cv::Mat _image_8u_rgb;
  std::vector<char> _image_vec_tmp;
W
serving  
wangguibao 已提交
64 65
};

W
wangguibao 已提交
66 67 68
}  // namespace serving
}  // namespace paddle_serving
}  // namespace baidu