MCPcopy Create free account
hub / github.com/apache/singa / ReadFile

Method ReadFile

examples/cpp/cifar10/cifar10.h:59–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57 return;
58}
59const 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
83const std::pair<Tensor, Tensor> Cifar10::ReadTrainData() {
84 Tensor images(Shape{kBatchSize * kTrainFiles, 3, kImageSize, kImageSize});

Callers

nothing calls this directly

Calls 1

CopyDataFromHostPtrMethod · 0.45

Tested by

no test coverage detected