!7 cmodule LearnDogsVsCats > DynSingleFunctionWithPrintLog { /*switchable*/ transient File dir = userDir("dev/dogs-vs-cats/train"); LPair scaledImages; void doIt { // load scaled down test images L allImageFiles = listImageFiles(dir); Map> markingsMap = mapKeyAndFunction loadImageFileMarkings(allImageFiles); pnlStruct(markingsMap); if (empty(markingsMap)) ret with print("No marked images found in " + dir); new Map iImages; for (File f : keys(markingsMap)) iImages.put(f, BWIntegralImage(loadImage2(f))); print("Have " + n2(iImages, "integral image") + ", total size: " + str_toM(deepObjectSize(iImages))); // make "random & vary" module RandomAndVary_Record rav = new(CloseToColorPredicate, color := new RandomAndVary_RGBInt, maxDistance := new RandomAndVary_Double); // optimize CloseToColorPredicate e = pairA(racerOptimize(rav, func(CloseToColorPredicate e) -> double { scoreColorPredicateByRect(e, scaledImages) }, minRuntimeUnless100 := 10.0)); print(e); showImage(renderColorPredicateOnTestImages(e, pairsA(scaledImages)); // use centroid to detect rects for (Pair p : scaledImages) { DoublePt pt = centroidForColorPredicate(e, p.a); if (pt == null) continue with print("No result"); double dist = ptDistance(pt, centerOfRect(p.b)); print(pt + " / " + centerOfRect(p.b)); print("Error: " + percentRatio(dist, hypotenuse(p.a.getWidth(), p.a.getHeight())) + "%"); } } }