-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict.js
More file actions
32 lines (27 loc) · 1.14 KB
/
predict.js
File metadata and controls
32 lines (27 loc) · 1.14 KB
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
const tf = require('@tensorflow/tfjs');
const tf_cpu = require('@tensorflow/tfjs-node'); // run on CPU
const nodegit = require('nodegit');
const localPath = require("path").join(__dirname, "tmp");
const data = require('./data');
const fileMetrics = require('./file_metrics');
if (process.argv.length < 3) {
console.log("supply a file");
process.exit(1);
} else {
run(process.argv[2]);
}
async function run(filename){
const repo = await nodegit.Repository.open(localPath);
const firstCommitOnMaster = await repo.getMasterCommit();
walker = repo.createRevWalk();
walker.push(firstCommitOnMaster.sha());
walker.sorting(nodegit.Revwalk.SORT.Time);
const historyCommits = walker.fileHistoryWalk(filename, 10000);
metrics = await fileMetrics.save(repo, historyCommits, filename, null);
metricsValues = Object.values(metrics);
const input = tf.tensor2d([Object.values(metricsValues)], [1, metricsValues.length]);
const model = await tf.loadModel('file://saved-model/model.json');
const predictOut = model.predict(input);
const logits = Array.from(predictOut.dataSync());
const winner = data.CLASSES[predictOut.argMax(-1).dataSync()[0]];
}