TLTR: caffe reads the lmdb file from the beginning.
I used the following code snippet to write out 1st channel of input data blob as image (tested on GoogleNet).
Step 1. Train from scratch, running for about 30 iterations (set batch size to 1 so each iteration output 1 image only), then stop.
Step 2. Move the output images to another folder, say TrainImages.
Step 3. Resume training from the solverstate file created at Step 1, running for about 30 iterations again, then stop.
Step 4. Move the output images to another folder, say ResumeImages.
Now compare output images in TrainImages and ResumeImages.
They are the same.
Which means that input images at iteration 31 (resumed from solverstate) are from beginning of lmdb file.
// debug code start
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/imgproc/imgproc.hpp>
int iteration = 0;
// debug code end
template <typename Dtype>
Dtype Net<Dtype>::ForwardFromTo(int start, int end) {
CHECK_GE(start, 0);
CHECK_LT(end, layers_.size());
Dtype loss = 0;
for (int i = start; i <= end; ++i) {
// LOG(ERROR) << "Forwarding " << layer_names_[i];
Dtype layer_loss = layers_[i]->Forward(bottom_vecs_[i], top_vecs_[i]);
loss += layer_loss;
if (debug_info_) { ForwardDebugInfo(i); }
///////////////////////////////////////////////////////////////////////
// debug code start
for (int top_id = 0; top_id < top_vecs_[i].size(); ++top_id) {
const Blob<Dtype>& blob = *top_vecs_[i][top_id];
const string& blob_name = blob_names_[top_id_vecs_[i][top_id]];
int phase = this->phase();
if (phase > 0) continue; // skip TEST phase
if (blob_name.compare("data") == 0) {
int numAxes = blob.num_axes();
if (numAxes > 3) {
int h = blob.shape(2);
int w = blob.shape(3);
const Dtype* data = blob.cpu_data();
float *raw = (float*)data;
cv::Mat img(h, w, CV_32FC1, raw);
cv::Mat cv_img;
img.convertTo(cv_img, CV_8UC1);
char buffer [32];
sprintf (buffer, "%d", iteration);
std::string sId = buffer;
std::string path = "/home/user/Desktop/tmp/" + sId + ".jpg";
cv::imwrite(path, cv_img);
iteration++;
}
}
}
// debug code end
///////////////////////////////////////////////////////////////////////
}
return loss;
}