Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jjzazuet committed Aug 19, 2024
1 parent 32f819b commit 445fc38
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 27 deletions.
3 changes: 0 additions & 3 deletions datasets/face-synthetics/README.md

This file was deleted.

63 changes: 53 additions & 10 deletions src/test/java/datasets/face_synthetics/KmFsEnsemble.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class KmFsEnsemble {
);

private final KmDet eyePup = new KmDet(
KmCascades.loadPico(KmCamTest.class.getResource("/eye-pup")),
KmCascades.loadPico(KmCamTest.class.getResource(KmIBugMark.EyePup.getClassPath())),
KmRegion.detectDefault()
.withDetectMax(8)
.withSizeMin(16)
Expand All @@ -24,7 +24,7 @@ public class KmFsEnsemble {
);

private final KmDet eyeCornerIn = new KmDet(
KmCascades.loadPico(KmCamTest.class.getResource("/eye-corner-in")),
KmCascades.loadPico(KmCamTest.class.getResource(KmIBugMark.EyeCornerIn.getClassPath())),
KmRegion.detectDefault()
.withDetectMax(16)
.withSizeMin(16)
Expand All @@ -33,7 +33,7 @@ public class KmFsEnsemble {
);

private final KmDet eyeCornerOut = new KmDet(
KmCascades.loadPico(KmCamTest.class.getResource("/eye-corner-out")),
KmCascades.loadPico(KmCamTest.class.getResource(KmIBugMark.EyeCornerOut.getClassPath())),
KmRegion.detectDefault()
.withDetectMax(16)
.withSizeMin(16)
Expand All @@ -42,9 +42,41 @@ public class KmFsEnsemble {
);

private final KmDet mouthCornerOut = new KmDet(
KmCascades.loadPico(KmCamTest.class.getResource("/mouth-corner-out")),
KmCascades.loadPico(KmCamTest.class.getResource(KmIBugMark.MouthCornerOut.getClassPath())),
KmRegion.detectDefault()
.withDetectMax(16)
.withDetectMax(8)
.withSizeMin(16)
.withSizeMax(96)
);

private final KmDet mouthLipUp = new KmDet(
KmCascades.loadPico(KmCamTest.class.getResource(KmIBugMark.MouthLipUp.getClassPath())),
KmRegion.detectDefault()
.withDetectMax(8)
.withSizeMin(16)
.withSizeMax(96)
);

private final KmDet mouthLipLow = new KmDet(
KmCascades.loadPico(KmCamTest.class.getResource(KmIBugMark.MouthLipLow.getClassPath())),
KmRegion.detectDefault()
.withDetectMax(8)
.withSizeMin(16)
.withSizeMax(96)
);

private final KmDet eyebrowCorner = new KmDet(
KmCascades.loadPico(KmCamTest.class.getResource(KmIBugMark.EyebrowCorner.getClassPath())),
KmRegion.detectDefault()
.withDetectMax(8)
.withSizeMin(16)
.withSizeMax(96)
);

private final KmDet eyebrowCenter = new KmDet(
KmCascades.loadPico(KmCamTest.class.getResource(KmIBugMark.EyebrowCenter.getClassPath())),
KmRegion.detectDefault()
.withDetectMax(8)
.withSizeMin(16)
.withSizeMax(96)
);
Expand All @@ -58,16 +90,27 @@ private KmBounds applySg(KmBounds b, KmAvg3F avg) {
}

public final KmEns ens = ens(face, b -> applySg(b, faceAvg)).withId("face")
.then(ens(eyebrowCorner, kb -> kb.shift(.25f, .45f).resize(.4f)).withId("r-ebr-cor-in"))
.then(ens(eyebrowCenter, kb -> kb.shift(.25f, .35f).resize(.4f)).withId("r-ebr-cnt"))
.then(ens(eyebrowCorner, kb -> kb.shift(.25f, .25f).resize(.4f)).withId("r-ebr-cor-out"))
.then(ens(eyePup, kb -> kb.shift(.4f, .3f).resize(.5f)).withId("r-ey"))
.then(ens(eyeCornerIn, kb -> kb.shift(.4f, .4f).resize(.2f)).withId("r-ec-in"))
.then(ens(eyeCornerOut, kb -> kb.shift(.4f, .2f).resize(.2f)).withId("r-ec-ou"))

.then(ens(eyebrowCorner, kb -> kb.shift(.25f, .55f).resize(.4f)).withId("l-ebr-cor-in"))
.then(ens(eyebrowCenter, kb -> kb.shift(.25f, .65f).resize(.4f)).withId("l-ebr-cnt"))
.then(ens(eyebrowCorner, kb -> kb.shift(.25f, .75f).resize(.4f)).withId("l-ebr-cor-out"))
.then(ens(eyePup, kb -> kb.shift(.4f, .7f).resize(.5f)).withId("l-ey"))
.then(ens(eyeCornerIn, kb -> kb.shift(.4f, .6f).resize(.2f)).withId("l-ec-in"))
.then(ens(eyeCornerOut, kb -> kb.shift(.4f, .8f).resize(.2f)).withId("l-ec-ou"))
.then(
ens(mouthCornerOut, kb -> kb.shift(.95f, .3f).resize(.4f)).withId("l-mc-out")
).then(
ens(mouthCornerOut, kb -> kb.shift(.95f, .7f).resize(.4f)).withId("r-mc-out")
);

.then(ens(mouthCornerOut, kb -> kb.shift(.85f, .3f).resize(.4f)).withId("r-mc-out"))
.then(ens(mouthLipUp, kb -> kb.shift(.75f, .3f).resize(.4f)).withId("r-ml-up"))
.then(ens(mouthLipLow, kb -> kb.shift(.95f, .3f).resize(.6f)).withId("r-ml-low"))

.then(ens(mouthCornerOut, kb -> kb.shift(.85f, .7f).resize(.4f)).withId("l-mc-out"))
.then(ens(mouthLipUp, kb -> kb.shift(.75f, .7f).resize(.4f)).withId("l-ml-up"))
.then(ens(mouthLipLow, kb -> kb.shift(.95f, .7f).resize(.6f)).withId("l-ml-low"))
;

}
20 changes: 9 additions & 11 deletions src/test/java/datasets/face_synthetics/KmFsGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static KmImageList loadImages(KmIBugMark mark, int limit) {
var kil = new KmImageList();
Collections.shuffle(fl);
var it = fl.iterator();
while (ik < limit) {
while (ik < limit && it.hasNext()) {
var img = it.next();
var segF = new File(img.getParentFile(), img.getName().replace(".png", "_seg.png"));
if (hasSegmentationClasses(segF, mark)) {
Expand Down Expand Up @@ -114,16 +114,14 @@ public static KmBuffer train(int maxTreesPerStage, int maxTreeDepth, float train
}

public static void main(String[] args) {
var mk = KmIBugMark.EyePup;
var images = loadImages(mk, 16384).updateSizeRange();

KmLogging.withLog(new KmTestLog().withLogInfo(true));
var kc = train(mk.maxTreesPerStage, mk.maxTreeDepth, mk.trainScale, images, true);
var kcOut = new File("./src/test/resources", mk.cascadeName);
OFnBlock.tryRun(() -> KmCascades.savePico(new FileOutputStream(kcOut), kc));
/*
*/

for (var mk : KmIBugMark.all) {
System.out.printf("Now training %s%n", mk);
var images = loadImages(mk, 8192).updateSizeRange();
KmLogging.withLog(new KmTestLog().withLogInfo(true));
var kc = train(mk.maxTreesPerStage, mk.maxTreeDepth, mk.trainScale, images, true);
var kcOut = new File("./src/test/resources", mk.cascadeName);
OFnBlock.tryRun(() -> KmCascades.savePico(new FileOutputStream(kcOut), kc));
}
/*
KmLogging.withLog(new KmTestLog().withLogInfo(false));
var models = KmFsGridSearch.apply(images);
Expand Down
17 changes: 16 additions & 1 deletion src/test/java/datasets/face_synthetics/KmIBugMark.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ public enum KmIBugMark {
EyeCornerIn(9, 20, 1.25f, new int[] {3, 4}, "eye-corner-in", IB40, IB43), // TODO ok, just needs more training data.
EyeCornerOut(9, 20, 1.20f, new int[] {3, 4}, "eye-corner-out", IB37, IB46), // TODO ok, just needs more training data.

MouthCornerOut(9, 16, 1.15f, new int[] {10, 11}, "mouth-corner-out", IB49, IB55)
MouthCornerOut(9, 16, 1.15f, new int[] {10, 11}, "mouth-corner-out", IB49, IB55),
MouthLipUp(8, 16, 1.1f, new int[] {10, 11}, "mouth-lip-up", IB51, IB53),
MouthLipLow(8, 16, 1.1f, new int[] {10, 11}, "mouth-lip-low", IB59, IB57),

EyebrowCorner(8, 16, 1.1f, new int[] {5, 6}, "eyebrow-corner", IB18, IB22, IB23, IB27),
EyebrowCenter(8, 16, 1.1f, new int[] {5, 6}, "eyebrow-center", IB20, IB25)
;

public static final KmIBugMark[] all = new KmIBugMark[] {
EyePup, EyeCornerIn, EyeCornerOut,
MouthCornerOut, MouthLipUp, MouthLipLow,
EyebrowCorner, EyebrowCenter
};

public final String cascadeName;
public final KmIBugPt[] points;
public final int[] requiredClasses;
Expand All @@ -30,6 +41,10 @@ public enum KmIBugMark {
this.requiredClasses = Objects.requireNonNull(requiredClasses);
}

public String getClassPath() {
return String.format("/%s", cascadeName);
}

@Override public String toString() {
return String.format(
"%s [maxTreeDepth: %d, maxTrees: %d, scale: %.04f]",
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/datasets/face_synthetics/KmIBugPt.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

public enum KmIBugPt {

IB18(18, 20, 1.2f),
IB22(22, 20, 1.2f),
IB23(23, 25, 1.2f),
IB27(27, 25, 1.2f),
IB20(20, 22, 1.2f),
IB25(25, 27, 1.2f),

IB40(40, 39, 1.3f),
IB43(43, 44, 1.3f),

Expand All @@ -18,6 +25,12 @@ public enum KmIBugPt {
IB49(49, 51, 1.5f),
IB55(55, 53, 1.5f),

IB51(51, 53, 1.2f),
IB53(53, 51, 1.2f),

IB59(59, 57, 1.1f),
IB57(57, 59, 1.1f),

IB69(69, 28, 1.4f), // face synthetics: right eye
IB70(70, 28, 1.4f), // face synthetics: left eye
;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/examples/KmCamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ private void drawRawDetections(Graphics2D g) {
var rX = c + (s / 2);
var rY = r + (s / 2);
circle.setFrameFromCenter(c, r, rX, rY);
g.draw(circle);
// g.draw(circle);
g.drawOval(c, r, 2, 2);
g.drawString(String.format("[%s]", e.getKey()), rX, rY);
// g.drawString(String.format("[%s]", e.getKey()), rX, rY);
}
}

Expand Down
Binary file modified src/test/resources/eye-corner-in
Binary file not shown.
Binary file modified src/test/resources/eye-corner-out
Binary file not shown.
Binary file modified src/test/resources/eye-pup
Binary file not shown.
Binary file added src/test/resources/eyebrow-center
Binary file not shown.
Binary file added src/test/resources/eyebrow-corner
Binary file not shown.
Binary file modified src/test/resources/mouth-corner-out
Binary file not shown.
Binary file added src/test/resources/mouth-lip-low
Binary file not shown.
Binary file added src/test/resources/mouth-lip-up
Binary file not shown.

0 comments on commit 445fc38

Please sign in to comment.