Skip to content

Commit db95c67

Browse files
authored
Update Box Rendering to display prediction score
Showing the prediction score gives more insight into the trained model and can help with debugging false positives.
1 parent d147954 commit db95c67

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/useBoxRenderer.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { useEffect } from 'react'
22

3+
const SCORE_DIGITS = 4
4+
5+
const getLabelText = (prediction) => {
6+
const scoreText = prediction.score.toFixed(SCORE_DIGITS)
7+
return prediction.class + ', score: ' + scoreText
8+
}
9+
310
const renderPredictions = (predictions, canvasRef) => {
411
const ctx = canvasRef.current.getContext('2d')
512
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height)
@@ -18,7 +25,7 @@ const renderPredictions = (predictions, canvasRef) => {
1825
ctx.strokeRect(x, y, width, height)
1926
// Draw the label background.
2027
ctx.fillStyle = '#00FFFF'
21-
const textWidth = ctx.measureText(prediction.class).width
28+
const textWidth = ctx.measureText(getLabelText(prediction)).width
2229
const textHeight = parseInt(font, 10) // base 10
2330
ctx.fillRect(x, y, textWidth + 4, textHeight + 4)
2431
})
@@ -28,7 +35,7 @@ const renderPredictions = (predictions, canvasRef) => {
2835
const y = prediction.bbox[1]
2936
// Draw the text last to ensure it's on top.
3037
ctx.fillStyle = '#000000'
31-
ctx.fillText(prediction.class, x, y)
38+
ctx.fillText(getLabelText(prediction), x, y)
3239
})
3340
}
3441

0 commit comments

Comments
 (0)