OpenCVUnlabeledDataSet::OpenCVUnlabeledDataSet(std::string classesListFile,
                                               std::string dataDirectory,
                                               std::string wildcard,
                                               int backgroundCol, bool loadData,
                                               int flags) {
  name = dataDirectory;
  header = "image";
  type = UNLABELEDBATCH;
  if (flags == 0)
    nFeatures = 1;
  if (flags == 1)
    nFeatures = 3;
  {
    std::ifstream f(classesListFile.c_str());
    std::string cl;
    int ctr = 0;
    while (f >> cl) {
      classes[cl] = ctr++;
      header += "," + cl;
    }
  }
  nClasses = classes.size();
  for (auto &file : globVector(dataDirectory + "/" + wildcard)) {
    OpenCVPicture *pic = new OpenCVPicture(file, backgroundCol, 0);
    pictures.push_back(pic);
  }
  if (loadData) {
    std::vector<std::thread> workers;
    int nThreads = 4;
    for (int nThread = 0; nThread < nThreads; ++nThread)
      workers.emplace_back(loadDataThread, &pictures, flags, nThread, nThreads);
    for (int nThread = 0; nThread < nThreads; ++nThread)
      workers[nThread].join();
  }
}
SpatiallySparseDataset ImageNet2012TrainSet() {
  SpatiallySparseDataset dataset;
  dataset.name="ImageNet2012 train set";
  dataset.type=TRAINBATCH;
  dataset.nFeatures=3;
  dataset.nClasses=1000;

  for (int cl=0;cl<1000;cl++) {
    for (auto &file : globVector(std::string("Data/imagenet2012/ILSVRC2012_img_train/")+classList[cl]+"/*.JPEG")) {
      dataset.pictures.push_back(new OpenCVPicture(file,128,cl));
    }
  }
  return dataset;
}
KagglePlanktonLabeledDataSet::KagglePlanktonLabeledDataSet
(std::string classesListFile, std::string dataDirectory, batchType type_, int backgroundCol) {
  name=dataDirectory;
  type=type_;
  {
    std::ifstream f(classesListFile.c_str());
    std::string cl;
    int ctr=0;
    while (f >> cl)
      classes[cl]=ctr++;
  }
  nClasses=classes.size();
  for (auto &kv : classes) {
    for (auto &file : globVector(dataDirectory+kv.first+"/*.jpg")) {
      OpenCVPicture* pic = new OpenCVPicture(file,-1,backgroundCol,kv.second);
      pic->loadDataWithoutScaling();
      nFeatures=pic->mat.channels();
      pic->scale=powf(powf(pic->mat.rows,2)+powf(pic->mat.cols,2),0.5);
      pictures.push_back(pic);
    }
  }
}
KagglePlanktonUnlabeledDataSet::KagglePlanktonUnlabeledDataSet
(std::string classesListFile, std::string dataDirectory, int backgroundCol) {
  name=dataDirectory;
  header="image";
  type=UNLABELEDBATCH;
  {
    std::ifstream f(classesListFile.c_str());
    std::string cl;
    int ctr=0;
    while (f >> cl) {
      classes[cl]=ctr++;
      header=header+","+cl;
    }
  }
  nClasses=classes.size();
  for (auto &file : globVector(std::string(dataDirectory+"*.jpg"))) {
    OpenCVPicture* pic = new OpenCVPicture(file,-1,backgroundCol,0);
    pic->loadDataWithoutScaling();
    nFeatures=pic->mat.channels();
    pic->scale=powf(powf(pic->mat.rows,2)+powf(pic->mat.cols,2),0.5);
    pictures.push_back(pic);
  }
}