forked from tensorflow/tfjs-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.js
80 lines (71 loc) · 2.24 KB
/
ui.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @license
* Copyright 2018 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import * as tfvis from '@tensorflow/tfjs-vis';
const statusElement = document.getElementById('status');
export function updateStatus(message) {
statusElement.innerText = message;
};
export async function plotLosses(trainLogs) {
return tfvis.show.history(
document.getElementById('plotLoss'), trainLogs, ['loss', 'val_loss'], {
width: 450,
height: 320,
xLabel: 'Epoch',
yLabel: 'Loss',
});
}
export async function plotAccuracies(trainLogs) {
tfvis.show.history(
document.getElementById('plotAccuracy'), trainLogs, ['acc', 'val_acc'], {
width: 450,
height: 320,
xLabel: 'Epoch',
yLabel: 'Accuracy',
});
}
const rocValues = [];
const rocSeries = [];
/**
* Plot a ROC curve.
* @param {number[]} fprs False positive rates.
* @param {number[]} tprs True positive rates, must have the same length as
* `fprs`.
* @param {number} epoch Epoch number.
*/
export async function plotROC(fprs, tprs, epoch) {
epoch++; // Convert zero-based to one-based.
// Store the series name in the list of series
const seriesName = 'epoch ' +
(epoch < 10 ? `00${epoch}` : (epoch < 100 ? `0${epoch}` : `${epoch}`))
rocSeries.push(seriesName);
const newSeries = [];
for (let i = 0; i < fprs.length; i++) {
newSeries.push({
x: fprs[i],
y: tprs[i],
});
}
rocValues.push(newSeries);
return tfvis.render.linechart(
document.getElementById('rocCurve'),
{values: rocValues, series: rocSeries},
{
width: 450,
height: 320,
},
);
}