mxnet
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
io.h
Go to the documentation of this file.
1 
6 #ifndef MXNET_IO_H_
7 #define MXNET_IO_H_
8 
9 #include <dmlc/data.h>
10 #include <dmlc/registry.h>
11 #include <vector>
12 #include <string>
13 #include <utility>
14 #include <queue>
15 #include "./base.h"
16 #include "./ndarray.h"
17 
18 namespace mxnet {
23 template<typename DType>
24 class IIterator : public dmlc::DataIter<DType> {
25  public:
30  virtual void Init(const std::vector<std::pair<std::string, std::string> >& kwargs) = 0;
32  virtual void BeforeFirst(void) = 0;
34  virtual bool Next(void) = 0;
36  virtual const DType &Value(void) const = 0;
38  virtual ~IIterator(void) {}
40  std::vector<std::string> data_names;
42  inline void SetDataName(const std::string data_name) {
43  data_names.push_back(data_name);
44  }
45 }; // class IIterator
46 
48 struct DataInst {
50  unsigned index;
52  std::vector<TBlob> data;
54  std::string extra_data;
55 }; // struct DataInst
56 
60 struct DataBatch {
62  std::vector<NDArray> data;
64  std::vector<uint64_t> index;
66  std::string extra_data;
69 }; // struct DataBatch
70 
72 typedef std::function<IIterator<DataBatch> *()> DataIteratorFactory;
77  : public dmlc::FunctionRegEntryBase<DataIteratorReg,
78  DataIteratorFactory> {
79 };
80 //--------------------------------------------------------------
81 // The following part are API Registration of Iterators
82 //--------------------------------------------------------------
95 #define MXNET_REGISTER_IO_ITER(name) \
96  DMLC_REGISTRY_REGISTER(::mxnet::DataIteratorReg, DataIteratorReg, name)
97 } // namespace mxnet
98 #endif // MXNET_IO_H_
std::vector< std::string > data_names
store the name of each data, it could be used for making NDArrays
Definition: io.h:40
void SetDataName(const std::string data_name)
set data name to each attribute of data
Definition: io.h:42
std::string extra_data
extra data to be fed to the network
Definition: io.h:54
int num_batch_padd
num of example padded to batch
Definition: io.h:68
std::vector< uint64_t > index
index of image data
Definition: io.h:64
unsigned index
unique id for instance
Definition: io.h:50
virtual const DType & Value(void) const =0
get current data
std::string extra_data
extra data to be fed to the network
Definition: io.h:66
NDArray interface that handles array arithematics.
iterator type
Definition: io.h:24
Registry entry for DataIterator factory functions.
Definition: io.h:76
virtual void Init(const std::vector< std::pair< std::string, std::string > > &kwargs)=0
set the parameters and init iter
virtual ~IIterator(void)
constructor
Definition: io.h:38
virtual bool Next(void)=0
move to next item
DataBatch of NDArray, returned by Iterator.
Definition: io.h:60
a single data instance
Definition: io.h:48
std::vector< TBlob > data
content of data
Definition: io.h:52
virtual void BeforeFirst(void)=0
reset the iterator
configuation of mxnet as well as basic data structure.
std::vector< NDArray > data
content of dense data, if this DataBatch is dense
Definition: io.h:62
std::function< IIterator< DataBatch > *()> DataIteratorFactory
typedef the factory function of data iterator
Definition: io.h:72