| 288 | } |
| 289 | |
| 290 | bool update() |
| 291 | { |
| 292 | if (mListFile.empty()) |
| 293 | { |
| 294 | std::string inputFileName = locateFile(mPrefix + std::to_string(mFileCount++) + mSuffix, mDataDir); |
| 295 | std::ifstream file(inputFileName.c_str(), std::ios::binary); |
| 296 | if (!file) |
| 297 | { |
| 298 | return false; |
| 299 | } |
| 300 | int d[4]; |
| 301 | file.read(reinterpret_cast<char*>(d), 4 * sizeof(int32_t)); |
| 302 | ASSERT(mDims.d[0] == d[0] && mDims.d[1] == d[1] && mDims.d[2] == d[2] && mDims.d[3] == d[3]); |
| 303 | file.read(reinterpret_cast<char*>(getFileBatch()), sizeof(float) * mDims.d[0] * mImageSize); |
| 304 | file.read(reinterpret_cast<char*>(getFileLabels()), sizeof(float) * mDims.d[0]); |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | std::vector<std::string> fNames; |
| 309 | std::ifstream file(locateFile(mListFile, mDataDir), std::ios::binary); |
| 310 | if (!file) |
| 311 | { |
| 312 | return false; |
| 313 | } |
| 314 | |
| 315 | sample::gLogInfo << "Batch #" << mFileCount << std::endl; |
| 316 | file.seekg(((mBatchCount * mBatchSize)) * 7); |
| 317 | |
| 318 | for (int i = 1; i <= mBatchSize; i++) |
| 319 | { |
| 320 | std::string sName; |
| 321 | std::getline(file, sName); |
| 322 | sName = sName + ".ppm"; |
| 323 | sample::gLogInfo << "Calibrating with file " << sName << std::endl; |
| 324 | fNames.emplace_back(sName); |
| 325 | } |
| 326 | |
| 327 | mFileCount++; |
| 328 | |
| 329 | const int imageC = 3; |
| 330 | const int imageH = 300; |
| 331 | const int imageW = 300; |
| 332 | std::vector<samplesCommon::PPM<imageC, imageH, imageW>> ppms(fNames.size()); |
| 333 | for (uint32_t i = 0; i < fNames.size(); ++i) |
| 334 | { |
| 335 | readPPMFile(locateFile(fNames[i], mDataDir), ppms[i]); |
| 336 | } |
| 337 | |
| 338 | std::vector<float> data(samplesCommon::volume(mDims)); |
| 339 | const float scale = 2.0 / 255.0; |
| 340 | const float bias = 1.0; |
| 341 | long int volChl = mDims.d[2] * mDims.d[3]; |
| 342 | |
| 343 | // Normalize input data |
| 344 | for (int i = 0, volImg = mDims.d[1] * mDims.d[2] * mDims.d[3]; i < mBatchSize; ++i) |
| 345 | { |
| 346 | for (int c = 0; c < mDims.d[1]; ++c) |
| 347 | { |
no test coverage detected