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
#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
wangguibao 已提交
30
#include "paddle_inference_api.h"  // NOLINT
W
serving  
wangguibao 已提交
31 32 33 34 35 36

namespace baidu {
namespace paddle_serving {
namespace serving {

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

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

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

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

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

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

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

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