Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show softmax score in session detail view #389

Merged
merged 2 commits into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions ui/src/data-services/models/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,35 @@ import { getFormatedTimeString } from 'utils/date/getFormatedTimeString/getForma

export type ServerCapture = any // TODO: Update this type

export type DetectionOccurrence = {
id: string
determination: {
name: string
}
determination_score: number
}

export type CaptureDetection = {
bbox: number[]
id: string
label: string
score: number
occurrenceId?: string
occurrence?: DetectionOccurrence
}

const makeDetectionLabel = (detection: CaptureDetection) => {
const occurrence: DetectionOccurrence | undefined = detection.occurrence;
if (occurrence && occurrence.determination) {
if (occurrence.determination_score) {
const scorePercentage = Math.round(occurrence.determination_score * 100).toString();
return `${occurrence.determination.name} (${scorePercentage}%)`;
}
return occurrence.determination.name;
}
return detection.id;
};

export class Capture {
protected readonly _capture: ServerCapture
private readonly _detections: CaptureDetection[] = []
Expand All @@ -18,16 +40,15 @@ export class Capture {
this._capture = capture

if (capture.detections?.length) {
this._detections = capture.detections.map((detection: any) => ({
bbox: detection.bbox,
id: `${detection.id}`,
label: detection.occurrence
? detection.occurrence.determination.name
: detection.id,
occurrenceId: detection.occurrence
? `${detection.occurrence.id}`
: undefined,
}))
this._detections = capture.detections.map((detection: CaptureDetection) => {
return {
bbox: detection.bbox,
id: `${detection.id}`,
label: makeDetectionLabel(detection),
score: detection.score,
occurrenceId: detection.occurrence ? `${detection.occurrence.id}` : undefined,
};
});
}
}

Expand Down