May 2020
Intermediate to advanced
530 pages
17h 8m
English
We read the labels file with the ReadLabels function:
void MNISTDataset::ReadLabels(const std::string& labels_file_name) { std::ifstream labels_file(labels_file_name, std::ios::binary | std::ios::binary); labels_file.exceptions(std::ifstream::failbit | std::ifstream::badbit); if (labels_file) { uint32_t magic_num = 0; uint32_t num_items = 0; if (read_header(&magic_num, labels_file) && read_header(&num_items, labels_file)) { labels_.resize(static_cast<size_t>(num_items)); labels_file.read(reinterpret_cast<char*>(labels_.data()), num_items); } }}
This function opens the file in binary mode and reads the header records, the magic number, and the number of items in the file. It also reads all the items directly to the C++ ...
Read now
Unlock full access