oneDNN Wrapper
data_loader.h
1 #include "oneapi/dnnl/dnnl.hpp"
2 #ifndef _DATA_LOADER
3 #define _DATA_LOADER
4 
5 #include <iostream>
6 #include <stdexcept>
7 #include <cmath>
8 #include <random>
9 #include <functional> // std::multiplies
10 #include <numeric> // std::accumulate
11 #include "intel_utils.h"
12 
18 class DataLoader{
19  public:
22  std::vector<float> dataset;
23  std::vector<float> dataset_labels;
24  std::vector<float> curr_batch;
25  std::vector<float> curr_batch_labels;
26  void write_to_memory(dnnl::memory dst_mem_features, dnnl::memory dst_mem_labels);
37  DataLoader(std::string features_path, std::string labels_path, int _minibatch_size, std::vector<int> dataset_shape, dnnl::engine _eng);
38  private:
39  int dataset_idx, sample_size;
40  void load_from_file(std::string filename, std::vector<float> &data);
41  dnnl::engine eng;
42 
43 };
44 
45 #endif
DataLoader allows to create a dataloader object to implement minibatch stochastic gradient descent.
Definition: data_loader.h:18
int dataset_size
Total number of samples.
Definition: data_loader.h:20
void write_to_memory(dnnl::memory dst_mem_features, dnnl::memory dst_mem_labels)
Method that writes the curr batch to memory and moves the index forward.
std::vector< float > curr_batch_labels
Vector containing the labels that will be written to the engine.
Definition: data_loader.h:25
std::vector< float > dataset_labels
Vector containing the labels.
Definition: data_loader.h:23
std::vector< float > curr_batch
Vector containing the current batch that will be written to the engine.
Definition: data_loader.h:24
int minibatch_size
Minibatch size.
Definition: data_loader.h:21
std::vector< float > dataset
Vector containing the entire dataset.
Definition: data_loader.h:22
DataLoader(std::string features_path, std::string labels_path, int _minibatch_size, std::vector< int > dataset_shape, dnnl::engine _eng)
Construct a new Data Loader object.