explicit ImageDetLabelMap()

in src/io/iter_image_det_recordio.cc [39:94]


  explicit ImageDetLabelMap(const char *path_imglist,
                            int label_width,
                            bool silent) {
    image_index_.clear();
    label_.clear();
    idx2label_.clear();
    dmlc::InputSplit *fi = dmlc::InputSplit::Create
        (path_imglist, 0, 1, "text");
    dmlc::InputSplit::Blob rec;
    while (fi->NextRecord(&rec)) {
      // quick manual parsing
      char *p = reinterpret_cast<char*>(rec.dptr);
      char *end = p + rec.size;
      // skip space
      while (isspace(*p) && p != end) ++p;
      image_index_.push_back(static_cast<size_t>(atol(p)));
      size_t start_pos = label_.size();
      if (label_width > 0) {
        // provided label_width > 0, require width check
        for (int i = 0; i < label_width; ++i) {
          // skip till space
          while (!isspace(*p) && p != end) ++p;
          // skip space
          while (isspace(*p) && p != end) ++p;
          CHECK(p != end) << "Bad ImageList format";
          label_.push_back(static_cast<real_t>(atof(p)));
        }
        CHECK_EQ(label_.size() - start_pos, label_width);
      } else {
        // arbitrary label width for each sample
        while (!isspace(*p) && p != end) ++p;
        while (isspace(*p) && p != end) ++p;
        char *curr = p;
        CHECK(curr != end) << "Bad ImageList format";
        while (!isspace(*p) && p != end) ++p;
        while (isspace(*p) && p != end) ++p;
        char *next = p;
        while (next != end) {
          label_.push_back(static_cast<real_t>(atof(curr)));
          curr = next;
          while (!isspace(*next) && next != end) ++next;
          while (isspace(*next) && next != end) ++next;
        }
        // skip the last one which should be the image_path
        CHECK_GT(label_.size(), start_pos) << "Bad ImageList format: empty label";
      }
      // record label start_pos and width in map
      idx2label_[image_index_.back()] = std::pair<size_t, size_t>(
        start_pos, label_.size() - start_pos);
    }
    delete fi;
    if (!silent) {
      LOG(INFO) << "Loaded ImageList from " << path_imglist << ' '
                << image_index_.size() << " Image records";
    }
  }