// // Created by yanlei on 16-9-19. // #include #include #include #include #include #include #include #include #include #include #include #include using namespace caffe; using namespace std; using namespace cv; typedef double Dtype; uint32_t swap_ending(uint32_t val) { val = ((val<<8)&0xFF00FF00)|((val>>8)&0xFF00FF); return (val<<16) | (val>>16); } int main(int argc, char** argv) { const char* image_filename = "/home/yanlei/caffe/data/mnist/train-images-idx3-ubyte"; const char* label_filename = "/home/yanlei/caffe/data/mnist/train-labels-idx1-ubyte"; //open files std::ifstream image_file(image_filename, std::ios::in|std::ios::binary); std::ifstream label_file(label_filename, std::ios::in|std::ios::binary); CHECK(image_file)<<"Unable to open file "<(&magic), 4); magic = swap_ending(magic); CHECK_EQ(magic, 2051)<<"Incorrect image file magic"; label_file.read(reinterpret_cast(&magic), 4); magic = swap_ending(magic); CHECK_EQ(magic, 2049)<<"Incorrect label file magic"; image_file.read(reinterpret_cast(&num_items), 4); num_items = swap_ending(num_items); label_file.read(reinterpret_cast(&num_labels), 4); num_labels = swap_ending(num_labels); CHECK_EQ(num_items, num_labels); image_file.read(reinterpret_cast(&rows), 4); rows = swap_ending(rows); image_file.read(reinterpret_cast(&cols), 4); cols = swap_ending(cols); cout<<"A total of "<