Spaces:
Sleeping
Sleeping
Commit ·
b12da17
1
Parent(s): 76265b8
✨ Implement FDI Non-Maximum Suppression to fix duplicate box counts
Browse files
toothmap_frontend/src/App.jsx
CHANGED
|
@@ -92,8 +92,14 @@ export default function App() {
|
|
| 92 |
|
| 93 |
// Pipeline / segmentation mode
|
| 94 |
if (pipelineResults) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
const showFDI = (mode === 'pipeline_yolo' || mode === 'pipeline_frcnn');
|
| 96 |
-
|
| 97 |
const [x1, y1, x2, y2] = box;
|
| 98 |
const rx = x1 * sx, ry = y1 * sy, rw = (x2 - x1) * sx, rh = (y2 - y1) * sy;
|
| 99 |
const col = showFDI ? getColour(fdi) : '#22d3ee';
|
|
@@ -155,6 +161,12 @@ export default function App() {
|
|
| 155 |
|
| 156 |
// Legend for pipeline mode
|
| 157 |
const quadrantNames = ['Q1 (Upper Right)', 'Q2 (Upper Left)', 'Q3 (Lower Left)', 'Q4 (Lower Right)'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
return (
|
| 160 |
<div className="min-h-screen flex flex-col bg-zinc-950 font-sans text-slate-200">
|
|
@@ -216,26 +228,26 @@ export default function App() {
|
|
| 216 |
)}
|
| 217 |
|
| 218 |
{/* Stats Panel */}
|
| 219 |
-
{(
|
| 220 |
<div className="bg-zinc-800/30 rounded-lg p-3 text-sm">
|
| 221 |
<p className="text-zinc-400 text-xs mb-1">Detected Teeth</p>
|
| 222 |
<p className="text-2xl font-bold text-white">
|
| 223 |
-
{
|
| 224 |
</p>
|
| 225 |
-
{
|
| 226 |
<div key={i} className="flex justify-between text-xs text-zinc-500 mt-1">
|
| 227 |
<span style={{ color: getColour(r.fdi) }}>FDI {r.fdi > 0 ? r.fdi : '?'}</span>
|
| 228 |
<span>{(r.confidence * 100).toFixed(0)}% conf</span>
|
| 229 |
</div>
|
| 230 |
))}
|
| 231 |
-
{
|
| 232 |
-
<p className="text-xs text-zinc-600 mt-1">+{
|
| 233 |
)}
|
| 234 |
</div>
|
| 235 |
)}
|
| 236 |
|
| 237 |
{/* Dental FDI Chart (Odontogram) */}
|
| 238 |
-
{(
|
| 239 |
<div className="bg-zinc-900/60 rounded-xl p-3 border border-zinc-800/80 shadow-inner">
|
| 240 |
<p className="text-[10px] font-bold text-slate-400 uppercase tracking-widest mb-3 text-center">FDI Dental Chart</p>
|
| 241 |
<div className="flex flex-col gap-1.5">
|
|
@@ -246,7 +258,7 @@ export default function App() {
|
|
| 246 |
return (
|
| 247 |
<div key={t}
|
| 248 |
className={`flex-1 aspect-[2/3] rounded-[2px] flex items-center justify-center text-[9px] font-bold transition-all ${
|
| 249 |
-
|
| 250 |
? 'bg-green-500/20 text-green-400 border border-green-500/40 shadow-[0_0_8px_rgba(34,197,94,0.15)]'
|
| 251 |
: 'bg-zinc-800 text-zinc-600 border border-zinc-700/40 opacity-70'
|
| 252 |
} ${isLeftQuad && idx === 7 ? 'mr-1.5' : ''}`}>
|
|
@@ -263,7 +275,7 @@ export default function App() {
|
|
| 263 |
return (
|
| 264 |
<div key={t}
|
| 265 |
className={`flex-1 aspect-[2/3] rounded-[2px] flex items-center justify-center text-[9px] font-bold transition-all ${
|
| 266 |
-
|
| 267 |
? 'bg-green-500/20 text-green-400 border border-green-500/40 shadow-[0_0_8px_rgba(34,197,94,0.15)]'
|
| 268 |
: 'bg-zinc-800 text-zinc-600 border border-zinc-700/40 opacity-70'
|
| 269 |
} ${isLeftQuad && idx === 7 ? 'mr-1.5' : ''}`}>
|
|
|
|
| 92 |
|
| 93 |
// Pipeline / segmentation mode
|
| 94 |
if (pipelineResults) {
|
| 95 |
+
// FDI-based Non-Maximum Suppression: keep only the highest confidence box per FDI class
|
| 96 |
+
const uniqueResults = Object.values(pipelineResults.reduce((acc, curr) => {
|
| 97 |
+
if (!acc[curr.fdi] || curr.confidence > acc[curr.fdi].confidence) acc[curr.fdi] = curr;
|
| 98 |
+
return acc;
|
| 99 |
+
}, {}));
|
| 100 |
+
|
| 101 |
const showFDI = (mode === 'pipeline_yolo' || mode === 'pipeline_frcnn');
|
| 102 |
+
uniqueResults.forEach(({ box, score, fdi, mask_base64 }) => {
|
| 103 |
const [x1, y1, x2, y2] = box;
|
| 104 |
const rx = x1 * sx, ry = y1 * sy, rw = (x2 - x1) * sx, rh = (y2 - y1) * sy;
|
| 105 |
const col = showFDI ? getColour(fdi) : '#22d3ee';
|
|
|
|
| 161 |
|
| 162 |
// Legend for pipeline mode
|
| 163 |
const quadrantNames = ['Q1 (Upper Right)', 'Q2 (Upper Left)', 'Q3 (Lower Left)', 'Q4 (Lower Right)'];
|
| 164 |
+
|
| 165 |
+
// Create filtered results for sidebar to prevent 50+ box hallucinations
|
| 166 |
+
const uniquePipelineResults = pipelineResults ? Object.values(pipelineResults.reduce((acc, curr) => {
|
| 167 |
+
if (!acc[curr.fdi] || curr.confidence > acc[curr.fdi].confidence) acc[curr.fdi] = curr;
|
| 168 |
+
return acc;
|
| 169 |
+
}, {})) : null;
|
| 170 |
|
| 171 |
return (
|
| 172 |
<div className="min-h-screen flex flex-col bg-zinc-950 font-sans text-slate-200">
|
|
|
|
| 228 |
)}
|
| 229 |
|
| 230 |
{/* Stats Panel */}
|
| 231 |
+
{(uniquePipelineResults || rawBoxes) && (
|
| 232 |
<div className="bg-zinc-800/30 rounded-lg p-3 text-sm">
|
| 233 |
<p className="text-zinc-400 text-xs mb-1">Detected Teeth</p>
|
| 234 |
<p className="text-2xl font-bold text-white">
|
| 235 |
+
{uniquePipelineResults ? uniquePipelineResults.length : rawBoxes.boxes.length}
|
| 236 |
</p>
|
| 237 |
+
{uniquePipelineResults && uniquePipelineResults.slice(0,6).map((r, i) => (
|
| 238 |
<div key={i} className="flex justify-between text-xs text-zinc-500 mt-1">
|
| 239 |
<span style={{ color: getColour(r.fdi) }}>FDI {r.fdi > 0 ? r.fdi : '?'}</span>
|
| 240 |
<span>{(r.confidence * 100).toFixed(0)}% conf</span>
|
| 241 |
</div>
|
| 242 |
))}
|
| 243 |
+
{uniquePipelineResults && uniquePipelineResults.length > 6 && (
|
| 244 |
+
<p className="text-xs text-zinc-600 mt-1">+{uniquePipelineResults.length - 6} more...</p>
|
| 245 |
)}
|
| 246 |
</div>
|
| 247 |
)}
|
| 248 |
|
| 249 |
{/* Dental FDI Chart (Odontogram) */}
|
| 250 |
+
{(uniquePipelineResults && mode.includes('pipeline')) && (
|
| 251 |
<div className="bg-zinc-900/60 rounded-xl p-3 border border-zinc-800/80 shadow-inner">
|
| 252 |
<p className="text-[10px] font-bold text-slate-400 uppercase tracking-widest mb-3 text-center">FDI Dental Chart</p>
|
| 253 |
<div className="flex flex-col gap-1.5">
|
|
|
|
| 258 |
return (
|
| 259 |
<div key={t}
|
| 260 |
className={`flex-1 aspect-[2/3] rounded-[2px] flex items-center justify-center text-[9px] font-bold transition-all ${
|
| 261 |
+
uniquePipelineResults.some(r => r.fdi === t)
|
| 262 |
? 'bg-green-500/20 text-green-400 border border-green-500/40 shadow-[0_0_8px_rgba(34,197,94,0.15)]'
|
| 263 |
: 'bg-zinc-800 text-zinc-600 border border-zinc-700/40 opacity-70'
|
| 264 |
} ${isLeftQuad && idx === 7 ? 'mr-1.5' : ''}`}>
|
|
|
|
| 275 |
return (
|
| 276 |
<div key={t}
|
| 277 |
className={`flex-1 aspect-[2/3] rounded-[2px] flex items-center justify-center text-[9px] font-bold transition-all ${
|
| 278 |
+
uniquePipelineResults.some(r => r.fdi === t)
|
| 279 |
? 'bg-green-500/20 text-green-400 border border-green-500/40 shadow-[0_0_8px_rgba(34,197,94,0.15)]'
|
| 280 |
: 'bg-zinc-800 text-zinc-600 border border-zinc-700/40 opacity-70'
|
| 281 |
} ${isLeftQuad && idx === 7 ? 'mr-1.5' : ''}`}>
|