Apache Singa
A General Distributed Deep Learning Library
encoder.h
1 
19 #ifndef SINGA_IO_ENCODER_H_
20 #define SINGA_IO_ENCODER_H_
21 
22 #include <vector>
23 #include <string>
24 #include "singa/core/tensor.h"
25 #include "singa/proto/io.pb.h"
26 
27 namespace singa {
28 
30 class Encoder {
31  public:
32  Encoder() {}
33  virtual ~Encoder() {}
34 
35  virtual void Setup(const EncoderConf& conf) {}
36 
39  virtual std::string Encode(vector<Tensor>& data) = 0;
40 };
41 
42 #ifdef USE_OPENCV
43 class JPGEncoder : public Encoder {
45  public:
46  void Setup(const EncoderConf& conf) override {
47  image_dim_order_ = conf.image_dim_order();
48  }
53  std::string Encode(vector<Tensor>& data) override;
54 
55  const std::string image_dim_order() const { return image_dim_order_; }
56 
57  private:
59  std::string image_dim_order_ = "CHW";
60 };
61 #endif // USE_OPENCV
62 
64 class CSVEncoder : public Encoder {
65  public:
66  void Setup(const EncoderConf& conf) override {}
70  std::string Encode(vector<Tensor>& data) override;
71 };
72 } // namespace singa
73 #endif // SINGA_IO_ENCODER_H_
Base encoder class that convert a set of tensors into string for storage.
Definition: encoder.h:30
Convert values from tensors into a csv formated string.
Definition: encoder.h:64
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: common.h:48
virtual std::string Encode(vector< Tensor > &data)=0
Format each sample data as a string, whose structure depends on the proto definition.