Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

48
LINES

< > BotCompany Repo | #1023110 // Make Face Detector [including face/no face, OK, but result not very good yet]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (10845L/78K).

!7

replace Finder with F1<RGBImage, Rect>.

sbool withNoFace = true;

p-exp {
  int w = 32;
  int limit = 95; // search for smallest finder with at least 95% accuracy
  
  File dir = ai_faceFinderDir();
  if (withNoFace) dir = newFile(dir, "with-no-face");
  
  L<RGBImageAndRect> marked = markedFaces_scaledToWidth(w, +withNoFace);
  FaceFinderByPictures1 finder = new(w, nonNulls(rgbImageAndRects_getClip(marked)));
  new Best<FaceFinderByPictures1> best;
  //double tolerance = first(images).image.getWidth()/2.0;
  
  best.put(racerOptimize(
    new RandomAndVary_Record<FaceFinderByPictures1>(
      finder,
      similarity := new RandomAndVary_Float),
    func(FaceFinderByPictures1 finder) -> double {
      video_scoreRect_step(new Best, marked, finder).score()
    }, plateauLength := 100));
  finder = best!;
  saveTextFileWithBackupVerbose(newFile(dir, "full-finder.struct"), struct(finder));

  //showImage(mergeRGBImagesAndRects(callFaceFinder(finder, rgbImageAndRects_images(marked))));
  
  new Best<Finder> best3;
  
  while (nempty(finder.pictures) && best.score() >= limit) {
    // Make finder smaller by removing pictures
    new Best<Finder> best2;
    for (int i = 0; i < l(finder.pictures); i++) {
      FaceFinderByPictures1 newFinder = shallowClone(finder);
      newFinder.pictures = listWithoutIndex(newFinder.pictures, i);
      //print("Took out image " + (i+1) + "/" + l(finder.pictures));
      video_scoreRect_step(best2, marked, newFinder, print := false);
      copyBestIfAtLeast(best2, best3, limit);
    }
    finder = (FaceFinderByPictures1) best2!;
    print("Got new finder with score " + best2.score() + ": " + finder);
  }
  
  saveTextFileWithBackupVerbose(newFile(dir, "smallest-finder-over-" + limit + ".struct"), struct(best3!));
}

Author comment

Began life as a copy of #1019536

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vdyxwxlmubrt, vouqrxazstgt

No comments. add comment

Snippet ID: #1023110
Snippet name: Make Face Detector [including face/no face, OK, but result not very good yet]
Eternal ID of this version: #1023110/8
Text MD5: fe621acabdaaaadd2f2a0e4bbd674c7a
Transpilation MD5: 6019e66e0bf58d5ef99fe8ce026c8840
Author: stefan
Category: javax / imaging
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-05-05 20:29:52
Source code size: 1825 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 291 / 892
Version history: 7 change(s)
Referenced in: [show references]