示例#1
0
void RunObjectness(CStr &resName, double base, int W, int NSS, int numPerSz)
{
	srand((unsigned int)time(NULL));
	DataSetVOC voc("../VOC2007/");
	voc.loadAnnotations();
	//voc2007.loadDataGenericOverCls();

	printf("Dataset:`%s' with %d training and %d testing\n", _S(voc.wkDir), voc.trainNum, voc.testNum);
	printf("%s Base = %g, W = %d, NSS = %d, perSz = %d\n", _S(resName), base, W, NSS, numPerSz);
	
	Objectness objNess(voc, base, W, NSS);

	vector<vector<Vec4i> > boxesTests;
	//objNess.getObjBndBoxesForTests(boxesTests, 250);

	//If running this for the first time, set preloadModel to false.
	//Although it is not tested, ensure that the model is generated by
	//the getObjBndBoxesForTestsFast function and not
	//the getObjBndBoxesForTests function which uses colour information too.

	//To avoid running out of memory, you can load images only during
	//prediction by setting preloadImages to false.

	bool preloadModel = true, preloadImages = false;
	objNess.getObjBndBoxesForTestsFast(boxesTests, numPerSz, preloadModel, preloadImages);
	objNess.getRandomBoxes(boxesTests);

	objNess.evaluatePerClassRecall(boxesTests, resName, numPerSz);
	objNess.illuTestReults(boxesTests);
}
示例#2
0
void RunObjectness(CStr &resName, double base, int W, int NSS, int numPerSz)
{
    srand((unsigned int) time(NULL));
    // DataSetVOC voc2007("/Datasets/VOC2007/");
    // voc2007.loadAnnotations();
    //voc2007.loadDataGenericOverCls();

    // printf("Dataset:`%s' with %d training and %d testing\n", _S(voc2007.wkDir), voc2007.trainNum, voc2007.testNum);
    // printf("%s Base = %g, W = %d, NSS = %d, perSz = %d\n", _S(resName), base, W, NSS, numPerSz);

    Objectness objNess(base, W, NSS);
    objNess.loadTrainedModel("/Datasets/VOC2007/model");
    // printf("Model\n");

    for(int i = 1; i < 10; i++)
    {
        string filename = format("/Datasets/VOC2007/JPEGImages/00001%d.jpg", i);
        printf("%s\n", filename.c_str());
        Mat img3u = imread(filename);
        ValStructVec<float, Vec4i> boxesTests;
        boxesTests.reserve(10000);
        objNess.getObjBndBoxes(img3u, boxesTests, numPerSz);

        int xmin, ymin, xmax, ymax;
        int num = boxesTests.size();
        printf("    %d\n", num);
        for (int j = 0; j < num; j++){
            Vec4i bb = boxesTests[j];
            xmin = bb[0];
            ymin = bb[1];
            xmax = bb[2];
            ymax = bb[3];
            // printf("    (%d, %d) -> (%d, %d)\n", xmin, ymin, xmax, ymax);
            rectangle(img3u, cvPoint(xmin, ymin), cvPoint(xmax, ymax), cvScalar(0, 0, 255), 3);
        }

        imshow(filename, img3u);
        waitKey(0);
    }


    // Objectness objNess(voc2007, base, W, NSS);
    // vector<vector<Vec4i> > boxesTests;
    // objNess.getObjBndBoxesForTests(boxesTests, 250);

    // objNess.getObjBndBoxesForTestsFast(boxesTests, numPerSz);
    //objNess.getRandomBoxes(boxesTests);

    //objNess.evaluatePerClassRecall(boxesTests, resName, 1000);
    //objNess.illuTestReults(boxesTests);
    //objNess.evaluatePAMI12();
    //objNess.evaluateIJCV13();
}
示例#3
0
int main(int argc, char* argv[])
{
    int W = 2, NSS = 8;
    double base = 2.0;
    if (argc < 2)
    {
        fprintf(stderr, "usage: work/directory/\n");
        return -1;
    }

    srand((unsigned int)time(NULL));
    DataSetVOC voc2007(argv[1]);
    voc2007.loadAnnotations();

    Objectness objNess(voc2007, base, W, NSS);

    objNess.evaluateIJCV13();
}
示例#4
0
文件: Main.cpp 项目: yun-liu/BING
void RunObjectness(CStr &resName, double base, int W, int NSS, int numPerSz)
{
	srand((unsigned int)time(NULL));
	DataSetVOC voc2007("C:/WkDir/DetectionProposals/VOC2007/");
	voc2007.loadAnnotations();
	//voc2007.loadDataGenericOverCls();

	cout << "Dataset:'" << _S(voc2007.wkDir) << "' with " << voc2007.trainNum << " training and " << voc2007.testNum << " testing" << endl;
	cout << _S(resName) << " Base = " << base << ", W = " << W << ", NSS = " << NSS << ", perSz = " << numPerSz << endl;

	Objectness objNess(voc2007, base, W, NSS);

	vector<vector<Vec4i>> boxes;
	//objNess.getObjBndBoxesForTests(boxes, 250);
	objNess.getObjBndBoxesForTestFast(boxes, numPerSz);
	//objNess.getRandomBoxes(boxes);
	//objNess.evaluatePerClassRecall(boxes, resName, 2000);
	//objNess.illuTestReults(boxes);
}
示例#5
0
文件: Main.cpp 项目: 20083017/CmCode
void RunObjectness(CStr &resName, double base, double intUionThr, int W, int NSS, int numPerSz)
{
	srand((unsigned int)time(NULL));
	//DataSetVOC voc2007("D:/WkDir/DetectionProposals/VOC2007/");
	DataSetVOC voc2007("./VOC2007/");
	voc2007.loadAnnotations();
	//voc2007.loadDataGenericOverCls();

	printf("Dataset:`%s' with %d training and %d testing\n", _S(voc2007.wkDir), voc2007.trainNum, voc2007.testNum);
	printf("%s Base = %g, intUionThr = %g, W = %d, NSS = %d, perSz = %d\n", _S(resName), base, intUionThr, W, NSS, numPerSz);
	
	Objectness objNess(voc2007, base, intUionThr, W, NSS);

	vector<vector<Vec4i>> boxesTests;
	//objNess.getObjBndBoxesForTests(boxesTests, 250);
	objNess.getObjBndBoxesForTestsFast(boxesTests, numPerSz);
	//objNess.getRandomBoxes(boxesTests);
	//objNess.evaluatePerClassRecall(boxesTests, resName, 1000);
	//objNess.illuTestReults(boxesTests);
}
示例#6
0
文件: Main.cpp 项目: q1kim/personness
void RunObjectness(CStr &resName, double base, double intUionThr, int W, int NSS, int numPerSz)
{
	srand((unsigned int)time(NULL));
	//DataSetVOC voc("../../DataSet/VOC2007/"); // BING Training
	DataSetVOC voc("../../DataSet/VOC2007/", true, true); // Personness Training
	//DataSetVOC voc("../../DataSet/VOC2012/", true, true); // Personness Test
	voc.loadAnnotations();
	//voc.loadDataGenericOverCls();

	printf("Dataset:`%s' with %d training and %d testing\n", _S(voc.wkDir), voc.trainNum, voc.testNum);
	printf("%s Base = %g, intUionThr = %g, W = %d, NSS = %d, perSz = %d\n", _S(resName), base, intUionThr, W, NSS, numPerSz);
	
	Objectness objNess(voc, base, intUionThr, W, NSS);

	vector<vector<Vec4i>> boxesTests;
	//objNess.getObjBndBoxesForTests(boxesTests, 250);
	objNess.getObjBndBoxesForTestsFast(boxesTests, numPerSz);
	//objNess.getRandomBoxes(boxesTests);
	//objNess.evaluatePerClassRecall(boxesTests, resName, 1000);
	objNess.illuTestReults(boxesTests);
	//objNess.chammoru_test();
}
示例#7
0
void bingQdpmRocTest(vector<string> &dirs,
					 int windowLimit = -1, double timeLimitMs = -1, float ratioThreshold = -1)
{
	size_t imageCount = 0;
	size_t personCount = 0;
	size_t matchCount = 0;
	vector<ScoreTp> pScores;
	TickMeter tm;
	vector<std::string>::const_iterator it = dirs.begin();
	char buf[512];

	for (; it != dirs.end(); it++) {
		string dir = *it;
		DataSetVOC voc(dir, true, true);
		voc.loadAnnotations();
		const size_t testNum = voc.testSet.size();
		const char *imgPath =_S(voc.imgPathW);

		// Objectness
		double base = 2;
		double intUionThr = 0.5;
		int W = 8;
		int NSS = 2;

#ifdef WINDOW_GUESS
		Objectness objNess(voc, base, intUionThr, W, NSS);

		objNess.loadTrainedModel(TRAIN_MODEL);
#endif

		// LSVM DPM
		string dpmPersonModel = "../ExtraData/latentsvmXml/person.xml";
		vector<string> models;
		models.push_back(dpmPersonModel);
		QUniLsvmDetector detector(models);
		float overlapThreshold = 0.2f;

		if (ratioThreshold > 0)
			detector.setRatioThreshold(ratioThreshold);

		printf("%d: \n", testNum);
		for (int i = 0; i < testNum; i++) {
			const vector<Vec4i> &boxesGT = voc.gtTestBoxes[i];
			const size_t gtNumCrnt = boxesGT.size();
			if (gtNumCrnt <= 0)
				continue;

			imageCount++;
			personCount += gtNumCrnt;

			Mat image = imread(format(imgPath, _S(voc.testSet[i])));
			if (image.ptr() == NULL) {
				fprintf(stderr, "No JPG Image !\n");
				exit(1);
			}

			int numPerSz = 130;
			ValStructVec<float, Vec4i> boxes;
			double preObj = tm.getTimeMilli();
			double objTime = 0.;

#ifdef WINDOW_GUESS // window guess
			tm.start();
			objNess.getObjBndBoxes(image, boxes, numPerSz);
			tm.stop();
			objTime = tm.getTimeMilli() - preObj;
#endif

			double localTimeLimitMs = timeLimitMs;
			if (timeLimitMs > 0) {
				localTimeLimitMs -= objTime;
				if (localTimeLimitMs < 0.)
					localTimeLimitMs = 0.;
			}

			vector<QRect> searchBoxes;
			if (windowLimit > 0) {
				for (int j = 0; j < (int)boxes.size() && j < windowLimit; j++) {
					const Vec4i &bb = boxes[j];
					QRect rt(bb[0], bb[1], bb[2], bb[3]);
					searchBoxes.push_back(rt);
				}
			} else {
				for (int j = 0; j < (int)boxes.size(); j++) {
					const Vec4i &bb = boxes[j];
					QRect rt(bb[0], bb[1], bb[2], bb[3]);
					searchBoxes.push_back(rt);
				}
			}

			tm.start();
			detector.setup(image, overlapThreshold, localTimeLimitMs);
			tm.stop();

			vector<FeatureMapCoord> ftrMapCoords;
#ifdef WINDOW_GUESS
			detector.cvtBox2FtrMapCoord(&searchBoxes, &ftrMapCoords);
#else
			detector.genFullFtrMapCoord(&ftrMapCoords);

			preObj = tm.getTimeMilli();
			tm.start();
#ifdef SHUFFLE_WINDOW
			random_shuffle(ftrMapCoords.begin(), ftrMapCoords.end());
#endif
			tm.stop();
			double randGenTime = tm.getTimeMilli() - preObj;

			if (localTimeLimitMs > 0 && localTimeLimitMs - preObj >= 0.)
					detector.setTimeLimit(localTimeLimitMs - preObj);
#endif

			vector<QUniLsvmDetector::ObjectDetection> detections;
			vector<vector<FeatureMapCoord> *> fmcss;
			fmcss.push_back(&ftrMapCoords);
			tm.start();
			detector.detect(detections, fmcss);
			tm.stop();

			vector<DetectedInfo> di(detections.size());
			vector<int> gtIdx(gtNumCrnt, -1);

			int detectCount = 0;
			for (size_t j = 0; j < detections.size(); j++) {
				const QUniLsvmDetector::ObjectDetection& od = detections[j];

				if (od.score < RECOMMENDABLE_THRESHOLD)
					continue;

				detectCount++;
				Vec4i bb(od.rect.x + 1, od.rect.y + 1, od.rect.x + od.rect.width, od.rect.y + od.rect.height);

				// score matchScore for the ROC curve
				double maxMatchScore = 0;
				int maxMatchId = -1;
				for (int k = 0; k < gtNumCrnt; k++) {
					double matchScore = DataSetVOC::interUnio(bb, boxesGT[k]);
					if (matchScore > maxMatchScore) {
						maxMatchScore = matchScore;
						maxMatchId = k;
					}
				}

				uchar match = maxMatchScore > 0.5 ? 1 : 0;
				if (match) {
					int preDetectedIdx = gtIdx[maxMatchId];
					if (preDetectedIdx >= 0) {
						if (maxMatchScore > di[preDetectedIdx].matchScore) {
							di[preDetectedIdx].matched = false;
							gtIdx[maxMatchId] = int(j);
							di[j].matchScore = maxMatchScore;
							di[j].matched = true;
						}
					} else {
						gtIdx[maxMatchId] = int(j);
						di[j].matchScore = maxMatchScore;
						di[j].matched = true;
					}
				}

#ifdef SAVE_IMAGE_RESULT
				// save the result image
				char buf[256];
				sprintf(buf, "%2f", od.score);
				Point pt(max((bb[2] + bb[0] - 85) / 2, 0), (bb[1] + bb[3]) / 2);
				putText(image, buf, pt, FONT_HERSHEY_SIMPLEX, 0.5, Scalar::all(255), 3, CV_AA);
				putText(image, buf, pt, FONT_HERSHEY_SIMPLEX, 0.5, Scalar::all(0), 1, CV_AA);
				rectangle(image, od.rect, cv::Scalar(0, 255, 0), 2);
#endif
			}

			for (size_t j = 0; j < detectCount; j++) { // detections are sorted in descending order
				const QUniLsvmDetector::ObjectDetection& od = detections[j];
				if (di[j].matched)
					matchCount++;
				pScores.push_back(ScoreTp(od.score, di[j].matched));
			}

#ifdef SAVE_IMAGE_RESULT
			imwrite((voc.testSet[i] + "_DpmResult.png").c_str(), image);
#endif
			printf("%d ", i + 1);
		}
		printf("\n");
	}
	printf("BingQdpmRocTest time = %f sec\n", tm.getTimeSec());
	printf("GT %d, Matched %d/%d \n", personCount, matchCount, pScores.size());

	// Calculate log-average miss rate
	stable_sort(begin(pScores), end(pScores),
		[](const ScoreTp &p1, const ScoreTp &p2) { return p1.first > p2.first; });

	vector<float> fp(pScores.size());
	for (size_t i = 0; i < fp.size(); i++)
		fp[i] = !pScores[i].second;

	vector<float> tp(pScores.size());
	tp[0] = pScores[0].second;
	for (size_t i = 1; i < tp.size(); i++)
		tp[i] = tp[i - 1] + pScores[i].second;
	for (size_t i = 0; i < tp.size(); i++)
		tp[i] /= personCount;

	for (size_t i = 1; i < fp.size(); i++)
		fp[i] += fp[i - 1];
	for (size_t i = 0; i < fp.size(); i++)
		fp[i] /= imageCount;

	sprintf(buf, "%s%03d_%03.fms_6137gt_%04dtp_%04ddt_%.0fs.m",
		METHOD_NAME, max(windowLimit, 0), timeLimitMs, matchCount, pScores.size(), tm.getTimeSec());
	FILE *matlabFile = fopen(buf, "w");
	printVector(matlabFile, tp, "tp");
	printVector(matlabFile, fp, "fp");

	char *matlabContent = "tp = tp'; fp = fp';\n"
		"addpath(genpath('d:/81_dataset/03_Caltech/piotr_toolbox/')); savepath;\n"
		"xs1=[-inf; fp];\n"
		"ys1=[0; tp];\n"
		"ref=10.^(-2:.25:0);\n"
		"lims=[3.1e-4 1e1 .5 1];\n"
		"m=length(ref);\n"
		"for i=1:m\n"
		"\tj=find(xs1<=ref(i));\n"
		"\tmiss(i)=ys1(j(end));\n"
		"end\n"
		"miss=exp(mean(log(max(1e-10,1-miss))));\n"
		"show=figure();\n"
		"plotRoc([fp tp],'logx',1,'logy',1,'xLbl','fppi',...\n"
		"\t'lims',lims,'color','g','smooth',1,'fpTarget',ref);\n"
		"title(sprintf('log-average miss rate = %.2f%%',miss*100));\n"
		"savefig(['MORU' 'Roc'],show,'png');\n";
	fwrite(matlabContent, strlen(matlabContent), 1, matlabFile);

	fclose(matlabFile);
}