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; }
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); } }