-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameClassification.ts
More file actions
40 lines (33 loc) · 1.31 KB
/
FrameClassification.ts
File metadata and controls
40 lines (33 loc) · 1.31 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
33
34
35
36
37
38
39
40
function hexToFloatArray(hexString: string): number[] {
const regex = /.{2}/g; // matches every 2 characters
const hexPairs = hexString.match(regex) || []; // split into pairs of hex characters
const array = hexPairs.map(hex => parseInt(hex, 16) / 255); // decode and scale each pair
return array;
}
export class FrameClassification {
NO_CAT?: number;
CAT_TRANSIT?: number;
CAT_CLEAR?: number;
CAT_PREY?: number;
HUMAN_ACTIVITY?: number;
constructor(classificationOutputs: number[] | string) {
if(!classificationOutputs) {
return;
}
if (typeof classificationOutputs === 'string') {
classificationOutputs = hexToFloatArray(classificationOutputs);
}
this.NO_CAT = classificationOutputs[0];
this.CAT_TRANSIT = classificationOutputs[1];
this.CAT_CLEAR = classificationOutputs[2];
this.CAT_PREY = classificationOutputs[3];
this.HUMAN_ACTIVITY = classificationOutputs[4];
}
get topK(): [string, number][] {
// Convert the classes object to an array of label/value pairs
const arrayOfPairs = Object.entries(this);
// Sort the array based on the value in descending order
const sortedPairs = arrayOfPairs.sort((a, b) => b[1] - a[1]);
return sortedPairs;
}
};