1 #ifndef CIFAR_LOADER_H_
2 #define CIFAR_LOADER_H_
19 std::string directory;
20 std::vector<std::string> trainFiles, testFiles;
26 : directory(directory)
42 trainFiles.push_back(
"data_batch_1.bin");
43 trainFiles.push_back(
"data_batch_2.bin");
44 trainFiles.push_back(
"data_batch_3.bin");
45 trainFiles.push_back(
"data_batch_4.bin");
46 trainFiles.push_back(
"data_batch_5.bin");
47 testFiles.push_back(
"test_batch.bin");
56 void load(std::vector<std::string>& file_names, Eigen::MatrixXd& inputs, Eigen::MatrixXd& outputs)
60 for(
int f = 0; f < file_names.size(); f++)
62 std::fstream file((directory +
"/" + file_names[f]).c_str(),
63 std::ios::in | std::ios::binary);
66 + file_names[f] +
"' in directory '"
68 for(
int n = 0; n <
NperFile; n++, instance++)
72 + file_names[f] +
".");
74 file.read(values,
D + 1);
75 if(values[0] < 0 || values[0] >=
F)
77 outputs.row(instance).setZero();
78 outputs.row(instance)(*
reinterpret_cast<unsigned char*
>(&values[0])) = 1.0;
81 for(
int c = 0; c <
C; c++)
83 for(
int x = 0; x <
X; x++)
85 for(
int y = 0;
y <
Y;
y++, idx++)
88 inputs(instance, idx) = ((double) * reinterpret_cast<unsigned char*>(&values[idx + 1])) / 128.0 - 1.0;
97 #endif // CIFAR_LOADER_H_