Apache Singa
A General Distributed Deep Learning Library
decoder.h
1 
19 #ifndef SINGA_IO_DECODER_H_
20 #define SINGA_IO_DECODER_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 {
29 class Decoder {
30  public:
31  Decoder() { }
32  virtual ~Decoder() { }
33 
34  virtual void Setup(const DecoderConf& conf) {}
35 
37  virtual std::vector<Tensor> Decode(std::string value) = 0;
38 };
39 
40 #ifdef USE_OPENCV
41 class JPGDecoder : public Decoder {
44  public:
45  void Setup(const DecoderConf& conf) override {
46  image_dim_order_ = conf.image_dim_order();
47  }
48  std::vector<Tensor> Decode(std::string value) override;
49 
50  const std::string image_dim_order() const { return image_dim_order_; }
51 
52  private:
54  std::string image_dim_order_ = "CHW";
55 };
56 #endif
57 
60 class CSVDecoder : public Decoder {
61  public:
62  void Setup(const DecoderConf& conf) override {
63  has_label_ = conf.has_label();
64  }
65  std::vector<Tensor> Decode(std::string value) override;
66 
67  const bool has_label() const { return has_label_; }
68 
69  private:
71  bool has_label_ = false;
72 };
73 } // namespace singa
74 #endif // SINGA_IO_DECODER_H_
Decode the string of csv formated data into data tensor (dtype is kFloat32) and optionally a label te...
Definition: decoder.h:60
virtual std::vector< Tensor > Decode(std::string value)=0
Decode value to get data and labels.
The base decoder that converts a string into a set of tensors.
Definition: decoder.h:29
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: common.h:48