Skip to content

Commit fec6739

Browse files
fix: fix bug that output conversion to percentage calculation was wrong
1 parent 9a47413 commit fec6739

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

web/src/components/CanvasBoard.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Cross2Icon } from '@radix-ui/react-icons';
44
import type * as ort from 'onnxruntime-web';
55

66
import './CanvasBoard.css';
7-
import { argMax, initOnnx, runInference, MNIST_IMAGE_SIDE_SIZE, getNumberColor } from 'utils/mnist';
7+
import { initOnnx, runInference, MNIST_IMAGE_SIDE_SIZE, getNumberColor } from 'utils/mnist';
88
import DonutChart from 'components/charts/DonutChart';
99
import type { PieSeriesOption } from 'echarts';
1010

@@ -44,7 +44,7 @@ function CanvasBoard() {
4444
}
4545

4646
ctx.beginPath();
47-
ctx.lineWidth = 30;
47+
ctx.lineWidth = 36;
4848
ctx.lineCap = 'round';
4949
ctx.strokeStyle = 'white';
5050
ctx.moveTo(pos.x, pos.y);
@@ -108,13 +108,11 @@ function CanvasBoard() {
108108
};
109109

110110
const donutChartData: PieSeriesOption['data'] = useMemo(() => {
111-
const highestIndex = argMax(inferenceList);
112111
const data: PieSeriesOption['data'] = Array.from(inferenceList)
113112
.map((d, i) => ({
114113
name: i.toString(),
115-
value: 10 - Math.abs(d),
114+
value: Math.exp(d), // pytorch/mnist.py uses log_softmax, so convert it back to linear from log
116115
itemStyle: { color: getNumberColor(i) },
117-
selected: i == highestIndex,
118116
}))
119117
.sort((a, b) => b.value - a.value);
120118
return data;

web/src/components/charts/DonutChart.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ function DonutChart({ data }: Props) {
1212
series: [
1313
{
1414
type: 'pie',
15-
selectedMode: 'single',
1615
radius: ['80%', '95%'],
1716
avoidLabelOverlap: true,
1817
itemStyle: { borderRadius: 5 },
19-
label: { formatter: '{b}', position: 'inside', fontSize: 20 },
18+
label: { formatter: '{b}', position: 'inside', fontSize: 15 },
2019
data,
2120
},
2221
],

0 commit comments

Comments
 (0)