caffe data layer相关层的继承结构
image-data-layer层关键代码注释
DataLayerSetUp函数
//将imagelist中的图片以 image+label格式 读入到 vector<pair<image,label>> lines_ 中
while (std::getline(infile, line)) {
pos = line.find_last_of(' ');
label = atoi(line.substr(pos + 1).c_str());
lines_.push_back(std::make_pair(line.substr(0, pos), label));
}
shuffle函数
template <typename Dtype>
void ImageDataLayer<Dtype>::ShuffleImages() {
caffe::rng_t* prefetch_rng =
static_cast<caffe::rng_t*>(prefetch_rng_->generator());
shuffle(lines_.begin(), lines_.end(), prefetch_rng);
}
load_batch函数
prefetch_label[item_id] = lines_[lines_id_].second;
// go to the next iter
lines_id_++;
//lines_id_ 全局变量,记录当前的index图片索引,如果索引大于epoch,则置0,从头开始,
//每个epoch shuffle一次
if (lines_id_ >= lines_size) {
// We have reached the end. Restart from the first.
DLOG(INFO) << "Restarting data prefetching from start.";
lines_id_ = 0;
if (this->layer_param_.image_data_param().shuffle()) {
ShuffleImages();
}
}