| 57 | return; |
| 58 | } |
| 59 | const std::pair<Tensor, Tensor> Cifar10::ReadFile(string file) { |
| 60 | Tensor images(Shape{kBatchSize, 3, kImageSize, kImageSize}); |
| 61 | Tensor labels(Shape{kBatchSize}, kInt); |
| 62 | if (dir_path_.back() != '/') dir_path_.push_back('/'); |
| 63 | LOG(INFO) << "Reading file " << dir_path_ + file; |
| 64 | std::ifstream data_file((dir_path_ + file).c_str(), |
| 65 | std::ios::in | std::ios::binary); |
| 66 | CHECK(data_file.is_open()) << "Unable to open file " << dir_path_ + file; |
| 67 | int label; |
| 68 | char image[kImageVol]; |
| 69 | float float_image[kImageVol]; |
| 70 | int tmplabels[kBatchSize]; |
| 71 | for (size_t itemid = 0; itemid < kBatchSize; ++itemid) { |
| 72 | // LOG(INFO) << "reading " << itemid << "-th image"; |
| 73 | ReadImage(&data_file, &label, image); |
| 74 | for (size_t i = 0; i < kImageVol; i++) |
| 75 | float_image[i] = static_cast<float>(static_cast<uint8_t>(image[i])); |
| 76 | images.CopyDataFromHostPtr(float_image, kImageVol, itemid * kImageVol); |
| 77 | tmplabels[itemid] = label; |
| 78 | } |
| 79 | labels.CopyDataFromHostPtr(tmplabels, kBatchSize); |
| 80 | return std::make_pair(images, labels); |
| 81 | } |
| 82 | |
| 83 | const std::pair<Tensor, Tensor> Cifar10::ReadTrainData() { |
| 84 | Tensor images(Shape{kBatchSize * kTrainFiles, 3, kImageSize, kImageSize}); |
nothing calls this directly
no test coverage detected