25 #ifndef CIFARIMPORTER_HPP_
26 #define CIFARIMPORTER_HPP_
40 template <
typename eT>
50 CIFARImporter(std::string node_name_ =
"cifar_importer", std::string data_filename_ =
"",
int min_sample_ = -1,
int max_sample_ = -1)
88 std::vector<std::string> names_array;
89 std::size_t pos = 0, found;
90 while((found = std::string(
data_filename).find_first_of(
';', pos)) != std::string::npos) {
92 names_array.push_back(std::string(
data_filename).substr(pos, found - pos));
97 names_array.push_back(std::string(
data_filename).substr(pos));
103 for (
size_t fi = 0; fi < names_array.size(); ++fi) {
106 LOG(LSTATUS) <<
"Opening file containing CIFAR file: " << names_array[fi];
107 std::ifstream cifar_file(names_array[fi], std::ios::in | std::ios::binary);
108 if (!cifar_file.is_open()) {
109 LOG(LFATAL) <<
"Oops! Couldn't find file: " << names_array[fi];
125 cifar_file.read(buffer, 1);
127 if (cifar_file.eof())
130 unsigned int temp_label = (
unsigned int)buffer[0];
133 LOG(LDEBUG) <<
"Loading sample: " << sample;
138 if (cifar_file.eof())
149 eT*
data = ptr->data();
157 size_t bi =
id*image_height*image_width + ih*image_width + iw;
162 data[bi] = (eT)((uint8_t)buffer[bi])/255.0f;
171 sample_labels.push_back(std::make_shared <unsigned int> (temp_label) );
178 LOG(LINFO) <<
"Imported " <<
sample_data.size() <<
" samples";
192 LOG(LINFO) <<
"Data import finished";
CIFARImporter(std::string node_name_="cifar_importer", std::string data_filename_="", int min_sample_=-1, int max_sample_=-1)
std::vector< std::shared_ptr< mic::types::Tensor< eT > > > & data()
Returns sample data.
mic::configuration::Property< int > max_sample
std::vector< size_t > sample_indices
Stores sample indices (sample "positions" in original dataset).
mic::configuration::Property< std::string > data_filename
Class responsible for importing CIFAR images. Returns a batch of Tensors.
virtual void initializePropertyDependentVariables()
Parent class for all data importers.
std::vector< std::shared_ptr< mic::types::Tensor< eT > > > sample_data
Stores the data.
#define MAKE_TENSOR_PTR(eT,...)
Macro for initialization of tensor pointer.
mic::configuration::Property< int > min_sample
Contains declaration (and definition) of base template class of all data importers.
typename std::shared_ptr< mic::types::Tensor< eT > > TensorPtr
Typedef for a shared pointer to template-typed dynamic matrices.
std::vector< std::shared_ptr< unsigned int > > sample_labels
Stores labels.
void setDataFilename(std::string data_filename_)
Contains declaration of tensor types.