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

67
LINES

< > BotCompany Repo | #1019262 // TrainVAD

JavaX fragment (include)

1  
sclass TrainVAD {
2  
  replace Recognizer with F1<BWImage, Bool>.
3  
    
4  
  new Best<Recognizer> best;
5  
  LPair<BWImage, Bool> trainingList;
6  
  float stepSizeRatio = 0.25f;
7  
  int clipLength;
8  
    
9  
  Recognizer go() {
10  
    final BWImage img1 = frequencyImage(voiceMegaMix());
11  
    final BWImage img2 = frequencyImage(nonVoiceMegaMix());
12  
    clipLength = iround(2.0*spectro_pixelsPerSecond());
13  
    int stepSize = max(1, iround(clipLength*stepSizeRatio));
14  
    print(+clipLength);
15  
    print(+stepSize);
16  
    L<BWImage> images1 = map(func(IntRange r) -> BWImage { bwHorizontalClip(img1, r) }, stepIntRange(clipLength, intRange(0, img1.getWidth()), stepSize));
17  
    L<BWImage> images2 = map(func(IntRange r) -> BWImage { bwHorizontalClip(img2, r) }, stepIntRange(clipLength, intRange(0, img2.getWidth()), stepSize));
18  
    print(allImageSizes(concatLists(images1, images2)));
19  
    print(l(images1) + " + " + l(images2) + " images");
20  
    
21  
    trainingList = trueFalseBPairs(images1, images2);
22  
    
23  
    // dummy recognizers first
24  
    
25  
    test(func(BWImage img) -> bool { false });
26  
    test(func(BWImage img) -> bool { true });
27  
    
28  
    new AIStrategy_RandomWithVariation<Recognizer> strategy;
29  
    strategy.best = best;
30  
    strategy.submit = f1_scorePreciseRecognizer(trainingList);
31  
    strategy.random = func -> Recognizer {
32  
      nu(VAD_1,
33  
        streakLength := random(1, clipLength/2),
34  
        threshold := randomFloat(),
35  
        band := audio_randomBand())
36  
    };
37  
    strategy.vary = func(Recognizer r) -> Recognizer {
38  
      if (r cast VAD_1)
39  
        ret nu(VAD_1,
40  
          streakLength := varyInt(r.streakLength),
41  
          threshold := varyFloat(r.threshold),
42  
          band := audio_varyBand(r.band));
43  
      null;
44  
    };
45  
    
46  
    runStrategyWhileImprovement(best, strategy);
47  
    
48  
    /*for (int streakLength = 1; streakLength <= clipLength/2; streakLength++)
49  
      test(nu(VAD_1, +streakLength));*/
50  
    
51  
    ret best!;
52  
  }
53  
  
54  
  void test(Recognizer r) {
55  
    scorePreciseRecognizer(best, r, trainingList);
56  
  }
57  
  
58  
  void showErrors(Recognizer r) {
59  
    if (r == null) ret;
60  
    new L<BWImage> errorImages;
61  
    for (Pair<BWImage, Bool> p : trainingList)
62  
      if (r.get(p.a) != p.b)
63  
        errorImages.add(bwAutoContrast(p.a));
64  
    if (nempty(errorImages))
65  
      showImage("Errors", mergeBWImagesVertically(errorImages));
66  
  }
67  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 12 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019262
Snippet name: TrainVAD
Eternal ID of this version: #1019262/2
Text MD5: 6fce017840486024fbec2d4a8af56229
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-28 17:44:06
Source code size: 2375 bytes / 67 lines
Pitched / IR pitched: No / No
Views / Downloads: 351 / 889
Version history: 1 change(s)
Referenced in: [show references]