-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
703 lines (444 loc) · 38.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="cordova.js"></script>
<script src="face-api.js"></script>
<script src="tfjs13-1.js"></script>
<script src="knn-classifier0-2-2.js"></script>
<script>
let myDebug = false
let myOkToTrain = false
var isPhoneGapWebView = location.href.match(/^file:/); // returns true for PhoneGap app
if (isPhoneGapWebView){
// document.writeln('<h1>I am cordova</h1>')
} else{
// document.writeln('<h1>I am a web browser</h1>')
}
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
myPhonegap()
restart()
/*
var script = document.createElement('script');
script.src = 'cordova.js';
document.head.appendChild(script);
*/
// alert('ready')
}
</script>
<div id="myDiv03"></div><br>
<input type=button style="font-size:25px; background-color:lime; " value=" Start " onclick="{
this.style.backgroundColor = 'LightGray'
restart()
myWebStart()
myClassifierLoad()
run()
myClock = setInterval('myNewPredict(myFaceLandmarks)',myInterval)
document.getElementById('myInt').value = myInterval
//document.getElementById('myPause').style.backgroundColor = 'Lime'
onPlay()
}">
<input type=button style="font-size:25px;" value="Switch to Environment" onclick="{
if (this.value == 'Switch to Environment'){
myCamera = 'environment'
this.value = 'Switch to User'
} else {
myCamera = 'user'
this.value = 'Switch to Environment'
}
videoEl.srcObject.getTracks().forEach(track => track.stop())
run()
}">
<input type=button style="font-size:25px;" value=Stop onclick="{
videoEl.srcObject.getTracks().forEach(track => track.stop())
clearInterval(myClock)
}"><br><br>
<input type=button id="myFaster" style="font-size:25px;" value=" Faster " onclick="{
this.style.backgroundColor = 'LightGray'
clearInterval(myClock)
if (myInterval > 250 ) {myInterval = myInterval - 200}
document.getElementById('myInt').value = myInterval
myClock = setInterval('myNewPredict(myFaceLandmarks)',myInterval)
}">
<input type=button style="font-size:25px;" value=" Slower " onclick="{
clearInterval(myClock)
if (myInterval < 6000 ) {myInterval = myInterval + 200}
document.getElementById('myInt').value = myInterval
myClock = setInterval('myNewPredict(myFaceLandmarks)',myInterval)
}">
<input type=button style="font-size:25px;" value=" Pause " onclick="{
clearInterval(myClock)
document.getElementById('myFaster').style.backgroundColor = 'Lime'
}">
<input type=number id="myInt" style="font-size:25px; width:100px;" readonly > ms
<input type="hidden" id="myInFile" size="120" value="https://hpssjellis.github.io/celeb2-classify/myClassifierModel01.json"> <br>
<input type=button style="font-size:25px;" value=" Train " onclick="{
myOkToTrain = true
document.getElementById('myClassText').style.display = 'inline' // can't as of yet save files with a mobile app
document.getElementById('myClassNumber').style.display = 'inline'
document.getElementById('myShowButton').style.display = 'inline'
document.getElementById('myGoogleButton').style.display = 'inline'
document.getElementById('myDataButton').style.display = 'inline'
document.getElementById('myClassText').style.visibility = 'visible'
document.getElementById('myClassNumber').style.visibility = 'visible'
document.getElementById('myShowButton').style.visibility = 'visible'
document.getElementById('myGoogleButton').style.visibility = 'visible'
document.getElementById('myDataButton').style.visibility = 'visible'
document.getElementById('myClassText').value = 'Enter Name here'
if (myDebug){
document.getElementById('mySaveButton').style.visibility = 'visible'
document.getElementById('myClearButton').style.visibility = 'visible'
document.getElementById('myClear2Button').style.visibility = 'visible'
document.getElementById('mySaveButton').style.display = 'inline'
document.getElementById('myClearButton').style.display = 'inline'
document.getElementById('myClear2Button').style.display = 'inline'
} else {
document.getElementById('myClearButton').click()
}
}">
<input type=text id="myClassText" style="font-size:25px; width:60%; visibility:hidden; display:inline" value = "Joe Smith" onFocus="{
this.value = '' // clear the value on entry
document.getElementById('myClassNumber').value = parseInt(document.getElementById('myClassNumber').value) + 1
// classifier.clearClass(parseInt(document.getElementById('myClassNumber').value))
clearInterval(myClock)
}">
<input type=number id="myClassNumber" style="font-size:25px; width:10%; visibility:hidden; display:inline" value = "0" onChange="{
document.getElementById('myClassText').value = myGroups[parseInt(document.getElementById('myClassNumber').value)]
const x = parseInt(document.getElementById('myClassNumber').value)
const myDataBlock = classifier.getClassExampleCount()[x]
document.getElementById('myDiv02').innerHTML = '#: '+ x + ', label: '+ myGroups[x] + ', with: '+myDataBlock+ ' records<br>'
}"> <br> <br>
<input type=button id="myClearButton" style="font-size:25px; visibility:hidden; display:inline" value = " Clear All " onClick="{
classifier.clearAllClasses()
clearInterval(myClock)
myGroups.length = 0
document.getElementById('myDiv02').innerHTML = 'You have to enter at least 2 names and numbers for the app to work. Also click the image to record the face'
document.getElementById('myFaster').style.backgroundColor = 'Lime'
document.getElementById('myClassNumber').value = -1
}">
<input type=button id="myClear2Button" style="font-size:25px; visibility:hidden; display:inline" value = " Clear Records " onClick="{
classifier.clearAllClasses()
clearInterval(myClock)
//myGroups.length = 0
document.getElementById('myDiv02').innerHTML = 'You have to enter at least 2 names and numbers for the app to work. Also click the image to record the face'
document.getElementById('myFaster').style.backgroundColor = 'Lime'
document.getElementById('myClassNumber').value = -1
}">
<input type=button id="mySaveButton" style="font-size:25px; visibility:hidden; display:inline" value=" Save Model " onclick="{
myClassifierSave()
}">
<input type=button id="myShowButton" style="font-size:25px; visibility:hidden; display:inline" value=" Check Training " onclick="{
myCheckGroups()
}">
<input type=button id="myGoogleButton" style="font-size:25px; visibility:hidden; display:inline" value=" Show Google " onclick="{
myShowInfo()
}">
<input type=button id="myDataButton" style="font-size:25px; visibility:hidden; display:inline" value=" Clear Present Face" onclick="{
myShowData()
}">
<div id="myDiv02">...</div><br>
<div id="videoDiv" onclick="{
// console.log(myFaceLandmarks)
if (myOkToTrain){
myNewTrain(myFaceLandmarks)
clearInterval(myClock)
document.getElementById('myFaster').style.backgroundColor = 'Lime'
document.getElementById('myDiv03').innerHTML = 'Saving faces while the App is open only. Click faster or slower to restart the app'
}
}">
<video onplay="onPlay(this)" id="inputVideo" autoplay muted width="640" height="480" style=" border: 1px solid #ddd;"></video><br>
<canvas id="overlay" width="640" height="480" style="position:relative; top:-487px; border: 1px solid #ddd;" ></canvas><br>
</div>
<div id="myDiv01"> <input type=button value="Clear Matches" onclick="{
myClearDiv()
}"></div><br>
</body>
<script>
////////////////////////// Globals ///////////////////////////////////////////
let stream
let myCamera = 'user'
const videoEl = document.getElementById('inputVideo')
classifier = knnClassifier.create();
console.log('knn-classifier loaded')
let myFaceLandmarks =[] //from face detection
//myFaceLandmarks.length = 0 // reset the array if needed.
let myGroups = [] // for storing classifier information
let newArray = []
let myIncomingClassifier = []
let myClock
let myInterval = 2000 // starting prediction time in ms
////////////////////////// A few helper functions ///////////////////////////////////////////
async function myWebStart(){
if(window.orientation == 0){
// portrait
stream = await navigator.mediaDevices.getUserMedia({video: { facingMode: myCamera, width:480, height:640 }, audio: false})
} else {
// landscape
stream = await navigator.mediaDevices.getUserMedia({video: { facingMode: myCamera, width:640, height:480 }, audio: false})
}
videoEl.srcObject = stream
}
function myPhonegap(){
if (isPhoneGapWebView){
if (window.plugin.CanvasCamera) {
window.plugin.CanvasCamera.initialize({
fullsize: window.document.getElementById('videoEl'),
});
var options = {
canvas: {
width: 640,
height: 480
},
capture: {
width: 640,
height: 480
},
use: 'file',
fps: 30,
cameraFacing: 'front'
};
window.plugin.CanvasCamera.start(options, function(error) {
console.log('[CanvasCamera start]', 'error', error);
}, function(data) {
// console.log('[CanvasCamera start]', 'data', data);
});
}
}
}
function restart(){
myOkToTrain = false
if (isPhoneGapWebView){
window.open = cordova.InAppBrowser.open;
}
document.getElementById('myClassText').style.display = 'none' // can't as of yet save files with a mobile app
document.getElementById('myClassNumber').style.display = 'none'
document.getElementById('mySaveButton').style.display = 'none' // can't as of yet save files with a mobile app
document.getElementById('myShowButton').style.display = 'none'
document.getElementById('myGoogleButton').style.display = 'none'
document.getElementById('myDataButton').style.display = 'none'
document.getElementById('myClearButton').style.display = 'none'
document.getElementById('myClear2Button').style.display = 'none'
}
function myClearDiv(){
document.getElementById('myDiv01').innerHTML = `
<input type=button value='Clear Matches' onclick='{
myClearDiv()
}'>`
}
function myOrient(){ // not using anymore
if(window.orientation == 0){
// portrait
document.getElementById('inputVideo').width = 480
document.getElementById('inputVideo').height = 640
document.getElementById('overlay').width = 480
document.getElementById('overlay').height = 640
document.getElementById('overlay').style.top = '-647px'
} else {
// lanscape default working
document.getElementById('inputVideo').width = 640
document.getElementById('inputVideo').height = 480
document.getElementById('overlay').width = 640
document.getElementById('overlay').height = 480
document.getElementById('overlay').style.top = '-487px'
}
}
window.addEventListener("orientationchange", function() {
// myOrient()
videoEl.srcObject.getTracks().forEach(track => track.stop())
run()
// if(window.orientation == 0){document.getElementById('myDiv02').innerHTML = '<h1>Portrait</h1>'} else {document.getElementById('myDiv02').innerHTML = '<h1>Landscape</h1>'}
}, false);
function resizeCanvasAndResults(dimensions, canvas, results) {
const { width, height } = dimensions instanceof HTMLVideoElement
? faceapi.getMediaDimensions(dimensions)
: dimensions
canvas.width = width
canvas.height = height
return results.map(res => res.forSize(width, height))
}
function drawDetections(dimensions, canvas, detections) {
const resizedDetections = resizeCanvasAndResults(dimensions, canvas, detections)
faceapi.drawDetection(canvas, resizedDetections)
}
function drawLandmarks(dimensions, canvas, results, withBoxes = true) {
const resizedResults = resizeCanvasAndResults(dimensions, canvas, results)
if (withBoxes) {
faceapi.drawDetection(canvas, resizedResults.map(det => det.detection))
}
const faceLandmarks = resizedResults.map(det => det.landmarks)
const drawLandmarksOptions = { lineWidth: 2, drawLines: true, color: 'green' }
faceapi.drawLandmarks(canvas, faceLandmarks, drawLandmarksOptions)
}
////////////////////////// The 2 Main functions ///////////////////////////////////////////
async function onPlay() {
// const videoEl = document.getElementById('inputVideo')
const options = new faceapi.TinyFaceDetectorOptions({ inputSize: 128, scoreThreshold : 0.3 })
result = await faceapi.detectSingleFace(videoEl, options).withFaceLandmarks(true)
if (result) {
myFaceLandmarks = result._unshiftedLandmarks._positions; // to pass to other areas
drawLandmarks(videoEl, document.getElementById('overlay'), [result], true)
// Just printing the first of 68 face landmark x and y
// document.getElementById('myDiv03').innerHTML = 'First of 68 face landmarks, x: '+
// Math.round(result._unshiftedLandmarks._positions[0]._x) + ', y: '+
// Math.round(result._unshiftedLandmarks._positions[0]._y) +'<br>'
}
setTimeout(() => onPlay())
}
async function run() {
if (isPhoneGapWebView){
// await faceapi.loadTinyFaceDetectorModel('file:///android_asset/www/')
// await faceapi.loadFaceLandmarkTinyModel('file:///android_asset/www/')
await faceapi.loadTinyFaceDetectorModel('https://www.rocksetta.com/party-app/')
await faceapi.loadFaceLandmarkTinyModel('https://www.rocksetta.com/party-app/')
} else {
// myOrient()
await faceapi.loadTinyFaceDetectorModel('https://hpssjellis.github.io/celeb2-classify/')
await faceapi.loadFaceLandmarkTinyModel('https://hpssjellis.github.io/celeb2-classify/')
}
}
//////////////////////////////////////////// start classifier stuff ///////////////////////////////////////////////////
myShowData = async function() { // actually clear one record
const x = parseInt(document.getElementById('myClassNumber').value)
const myDataBlock = classifier.getClassExampleCount()[x]
document.getElementById('myDiv02').innerHTML = '#: '+ x + ', label: '+ myGroups[x] + ', with: '+myDataBlock+ ' records<br>'
classifier.clearClass(x)
const myDataBlock2 = classifier.getClassExampleCount()[x]
document.getElementById('myDiv02').innerHTML += '#: '+ x + ', label: '+ myGroups[x] + ', with: '+myDataBlock2+ ' records<br>'
}
myCheckGroups = async function() {
document.getElementById('myDiv01').innerHTML = '' // clear it
for (let x=0; x < myGroups.length; x++){
const myDataBlock = classifier.getClassExampleCount()[x]
if (myGroups[x] == undefined) {
document.getElementById('myDiv01').innerHTML += '<font color=red>#: '+ x + ', label: </font><br>'
} else {
document.getElementById('myDiv01').innerHTML += '#: '+ x + ', label: '+ myGroups[x] + ', with: '+myDataBlock+ ' records<br>'
}
}
}
myShowInfo = async function() {
// myIn = document.getElementById('myArray01').value.split('***') // made it global
document.getElementById('myDiv01').innerHTML = '' // clear it
for (myIteration = 0; myIteration < myGroups.length; myIteration++){
// myIncomingImages[myIteration] = [] // make new part of 2D array
// myIncomingImages[myIteration] = myIn[myIteration].split(',') // [0] = groups, [1] = labels, [2] = Image URL
document.getElementById('myDiv01').innerHTML += `<a href='https://www.google.com/search?&tbm=isch&q=`+myGroups[myIteration]+`' target='_blank'>`+myIteration+`: `+myGroups[myIteration]+ `</a>, <br> `
// document.getElementById('myDiv-1').innerHTML += `<a href='${myGroups[myIteration]}'>Image Only</a><br>`
}
}
myNewTrain = async function(myDetectMarks){
for (let j=0; j < myDetectMarks.length; j++ ){
newArray[j] = []
newArray[j][0] = myDetectMarks[j].x
newArray[j][1] = myDetectMarks[j].y
}
classifier.addExample(tf.tensor2d(newArray, shape=[68,2]), parseInt(document.getElementById('myClassNumber').value));
myGroups[document.getElementById('myClassNumber').value] = document.getElementById('myClassText').value.replace(' ','_') // get rid of spaces
const myAddCount = classifier.getClassExampleCount()[document.getElementById('myClassNumber').value]
const myGroupNumber = document.getElementById('myClassNumber').value
document.getElementById('myDiv02').innerHTML = 'Group #: '+ myGroupNumber +
', with Label:'+document.getElementById('myClassText').value + ', number of times:' + myAddCount
}
myNewPredict = async function(myDetectMarks){
if ((classifier.getNumClasses() >= 1) && (myDetectMarks.length >= 1)) {
for (let j=0; j < myDetectMarks.length; j++ ){
newArray[j] = []
newArray[j][0] = myDetectMarks[j].x
newArray[j][1] = myDetectMarks[j].y
}
const myFindMatch = await classifier.predictClass(tf.tensor2d(newArray, shape=[68,2]), 3); // number of groups
console.log(myFindMatch)
document.getElementById('myClassText').value = myGroups[myFindMatch.classIndex]
document.getElementById('myClassNumber').value = myFindMatch.classIndex
// document.getElementById('myDiv01').innerHTML = 'Nearest: <span style=color:blue; onclick={myLoadOneImage('+myFindMatch.classIndex+')}>'+myGroups[myFindMatch.classIndex]+ '</span><br>' + document.getElementById('myDiv01').innerHTML
document.getElementById('myDiv01').innerHTML = `<input type=button onclick=window.open('https://www.google.com/search?&tbm=isch&q=`+myGroups[myFindMatch.classIndex]+`','_blank') value=`+myGroups[myFindMatch.classIndex]+ `><br>` + document.getElementById('myDiv01').innerHTML
document.getElementById('myDiv02').innerHTML = `<input type=button onclick=window.open('https://www.google.com/search?&tbm=isch&q=`+myGroups[myFindMatch.classIndex]+`','_blank') value=`+myGroups[myFindMatch.classIndex]+ `><br>`
} // if classifier
}
myDefineClassifierModel = async function(myPassedClassifier){
let myLayerList = []
myLayerList[0] = [] // for the input layer name as a string
myLayerList[1] = [] // for the input layer
myLayerList[2] = [] // for the concatenate layer name as a string
myLayerList[3] = [] // for the concatenate layer
let myMaxClasses = myPassedClassifier.getNumClasses()
//console.log('myPassedClassifier.getNumClasses()')
//console.log(myMaxClasses)
for (let myClassifierLoop = 0; myClassifierLoop < myMaxClasses; myClassifierLoop++ ){ // need number of classifiers
//console.log(myPassedClassifier.getClassifierDataset()[myClassifierLoop])
//console.log('shape first layer =')
//console.log(myPassedClassifier.getClassifierDataset()[myClassifierLoop].shape[0])
myLayerList[0][myClassifierLoop] = 'myInput' + myClassifierLoop // input name as a string
console.log('define input for'+myClassifierLoop)
myLayerList[1][myClassifierLoop] = tf.input({shape: myPassedClassifier.getClassifierDataset()[myClassifierLoop].shape[0], name: myLayerList[1][myClassifierLoop]}); // Define input layer
console.log('define dense for: '+myClassifierLoop)
myLayerList[2][myClassifierLoop] = 'myInput'+myClassifierLoop+'Dense1' // concatenate as a string
myLayerList[3][myClassifierLoop] = tf.layers.dense({units: 136, name: myGroups[myClassifierLoop]}).apply(myLayerList[1][myClassifierLoop]); //Define concatenate layer
}
// what the layers used to look like before the loop
//const myInput2 = tf.input({shape: [1], name: 'myInput2'});
//const myInput2Dense1 = tf.layers.dense({units: 20, name: 'myInput2Dense1'}).apply(myInput2);
console.log('Concatenate Paths')
const myConcatenate1 = tf.layers.concatenate({axis : 1, name: 'myConcatenate1'}).apply(myLayerList[3]); // send the entire list of dense
const myConcatenate1Dense4 = tf.layers.dense({units: 1, name: 'myConcatenate1Dense4'}).apply(myConcatenate1)
console.log('Define Model')
const myClassifierModel = tf.model({inputs: myLayerList[1], outputs: myConcatenate1Dense4}); // This would be a global model. With list of inputs as an array
//myClassifierModel.summary() // show a summary of the load
//console.log('myClassifierModel.layers[myMaxClasses]')
//console.log(myClassifierModel.layers[myMaxClasses])
myPassedClassifier.getClassifierDataset()[0].print(true)
for (let myClassifierLoop = 0; myClassifierLoop < myMaxClasses; myClassifierLoop++ ){ // since the first layers are inputs must add maxClasses
const myInWeight = await myPassedClassifier.getClassifierDataset()[myClassifierLoop]
myClassifierModel.layers[myClassifierLoop + myMaxClasses].setWeights([myInWeight, tf.ones([136])]); //model.layers[0].setWeights([tf.ones([10, 2]), tf.ones([2])]);
}
return myClassifierModel
}
///////////////////////////////////////////////////////////////////////////////
myClassifierSave = async function(){
const myClassifierModel2 = await myDefineClassifierModel(classifier) // pass global classifier
myClassifierModel2.save('downloads://myClassifierModel01')
//myClassifierModel2.summary(null,null,x => {document.getElementById('myDivSummary').innerHTML += x + '<br>'});
}
/////////////////////////////////////////////
mySetClassiferModelWeights = async function(){
}
//////////////////////////////////////////////////////////////////////////////
myClassifierLoad = async function(){
// note global variable called myIncomingClassifier
if (isPhoneGapWebView){
// document.getElementById('myInFile').value = 'file:///android_asset/www/myClassifierModel01.json' // correct path for Android App
document.getElementById('myInFile').value = 'https://www.rocksetta.com/party-app/myClassifierModel01.json' // correct path for Android App
}
const myLoadedModel = await tf.loadModel(document.getElementById('myInFile').value)
console.log('myLoadedModel.layers.length')
console.log(myLoadedModel.layers.length)
// console.log('myLoadedModel.layers[0].batchInputShape[1]')
// console.log(myLoadedModel.layers[0].batchInputShape[1] )
const myMaxLayers = myLoadedModel.layers.length
const myDenseEnd = myMaxLayers - 2
const myDenseStart = myDenseEnd/2 // assume 0 = first layer: if 6 layers 0-1 input, 2-3 dense, 4 concatenate, 5 dense output
for (let myWeightLoop = myDenseStart; myWeightLoop < myDenseEnd; myWeightLoop++ ){ // need number of classifiers
// console.log('myLoadedModel.layers['+myWeightLoop+']')
// console.log(myLoadedModel.layers[myWeightLoop])
// console.log('myLoadedModel.layers['+myWeightLoop+'].getWeights()[0].print(true)')
// myLoadedModel.layers[myWeightLoop].getWeights()[0].print(true)
myIncomingClassifier[myWeightLoop - myDenseStart] = myLoadedModel.layers[myWeightLoop].getWeights()[0]
myGroups[myWeightLoop - myDenseStart] = myLoadedModel.layers[myWeightLoop].name // hopefully the name is the group name
}
// console.log('Printing all the incoming classifiers')
// for (x=0; x < myIncomingClassifier.length ; x++){
// myIncomingClassifier[x].print(true)
// }
console.log('Activating Classifier')
classifier.dispose() // clear old classifier
classifier.setClassifierDataset(myIncomingClassifier)
console.log('Classifier loaded')
}
///////////////////////////////////// End KNN- Classifier stuff /////////////////////////////////////
</script>
Use at your own risk: Android App by Jeremy Ellis. <br>
Deep Learning interface, <b>face-api.js</b> by <b>@justadudewhohax</b>
simplified for beginners by <b>@rocksetta</b>
Simplified github <b>https://github.com/hpssjellis/face-api.js-for-beginners</b><br>
</body>
</html>