コード例 #1
0
Picture *OpenCVPicture::distort(RNG &rng, batchType type) {
  OpenCVPicture *pic = new OpenCVPicture(*this);
  if (epoch <= 800 and type == TRAINBATCH) {
    // 2x2 identity matrix:
    // Generate an affine distortion matrix
    float c00 = 1, c01 = 0, c10 = 0, c11 = 1;
    c00 *= 1 + rng.uniform(-0.2, 0.2); // x stretch
    c11 *= 1 + rng.uniform(-0.2, 0.2); // y stretch
    if (rng.randint(2) == 0)           // Horizontal flip
      c00 *= -1;
    int r = rng.randint(3);
    float alpha = rng.uniform(-0.2, 0.2);
    if (r == 0) // Slant
      matrixMul2x2inPlace(c00, c01, c10, c11, 1, 0, alpha, 1);
    if (r == 1) // Slant
      matrixMul2x2inPlace(c00, c01, c10, c11, 1, alpha, 0, 1);
    if (r == 2) // Rotate
      matrixMul2x2inPlace(c00, c01, c10, c11, cos(alpha), -sin(alpha),
                          sin(alpha), cos(alpha));
    pic->affineTransform(c00, c01, c10, c11);
    pic->jiggle(rng, 16);
    pic->colorDistortion(rng, 25.5, 0.15, 2.4, 2.4);
  }
  return pic;
}
コード例 #2
0
Picture *OpenCVPicture::distort(RNG &rng, batchType type) {
  OpenCVPicture *pic = new OpenCVPicture(*this);
  pic->loadDataWithoutScaling(0);
  float c00 = 1, c01 = 0, // 2x2 identity matrix---starting point for
                          // calculating affine distortion matrix
      c10 = 0, c11 = 1;
  float r, alpha, beta, s = 1;
  if (type == TRAINBATCH) {
    r = rng.uniform(-0.1, 0.1);
    alpha = rng.uniform(0, 2 * 3.1415926535);
    beta = rng.uniform(-0.2, 0.2) + alpha;
  } else {
    r = 0;
    alpha = rng.uniform(0, 2 * 3.1415926535);
    beta = alpha;
  }
  c00 = (1 + r) * cos(alpha);
  c01 = (1 + r) * sin(alpha);
  c10 = -(1 - r) * sin(beta);
  c11 = (1 - r) * cos(beta);
  if (rng.randint(2) == 0) {
    c00 *= -1;
    c01 *= -1;
  } // Horizontal flip
  pic->affineTransform(c00, c01, c10, c11);
  pic->jiggle(rng, 300);
  return pic;
}
コード例 #3
0
void loadDataThread(std::vector<Picture *> *pictures, int flags, int k, int n) {
  for (; k < pictures->size(); k += n) {
    OpenCVPicture *pic = dynamic_cast<OpenCVPicture *>(pictures->at(k));
    // pic->loadDataWithoutScaling(flags);
    pic->loadDataWithoutScalingRemoveModalColor();
    std::cout << "!" << std::flush;
  }
}
コード例 #4
0
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);
    }
  }
}
コード例 #5
0
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);
  }
}