-
Notifications
You must be signed in to change notification settings - Fork 1
/
finetune.js
58 lines (36 loc) · 1.3 KB
/
finetune.js
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
const classifier = knnClassifier.create();
let net;
const addExample = async (imgid, classId) => {
console.log("\nadding...")
const img = document.getElementById(imgid);
const activation = net.infer(img, true);
classifier.addExample(activation, classId);
console.log(" DONE")
};
const birdornot = async(imgid) => {
console.log("\npredicting...")
const img = document.getElementById(imgid);
const activation = net.infer(img, 'conv_preds');
const result = await classifier.predictClass(activation);
const classes = ['Bird', 'Not Bird'];
console.log("label", result.label)
console.log("prediction: ", classes[result.label])
console.log("probability: ", result.confidences[result.label])
}
const catordog = async(imgid) => {
console.log("\npredicting...")
const img = document.getElementById(imgid);
const activation = net.infer(img, 'conv_preds');
const result = await classifier.predictClass(activation);
const classes = ['Cat', 'Dog'];
console.log("label", result.label)
console.log("prediction: ", classes[result.label])
console.log("probability: ", result.confidences[result.label])
}
async function app() {
console.log('Loading mobilenet..');
// Load the model.
net = await mobilenet.load();
console.log('Successfully loaded model');
}
app();