| 31 | } |
| 32 | |
| 33 | export function showTestResults(batch, predictions, labels) { |
| 34 | const testExamples = batch.xs.shape[0]; |
| 35 | imagesElement.innerHTML = ''; |
| 36 | for (let i = 0; i < testExamples; i++) { |
| 37 | const image = batch.xs.slice([i, 0], [1, batch.xs.shape[1]]); |
| 38 | |
| 39 | const div = document.createElement('div'); |
| 40 | div.className = 'pred-container'; |
| 41 | |
| 42 | const canvas = document.createElement('canvas'); |
| 43 | canvas.className = 'prediction-canvas'; |
| 44 | draw(image.flatten(), canvas); |
| 45 | |
| 46 | const pred = document.createElement('div'); |
| 47 | |
| 48 | const prediction = predictions[i]; |
| 49 | const label = labels[i]; |
| 50 | const correct = prediction === label; |
| 51 | |
| 52 | pred.className = `pred ${(correct ? 'pred-correct' : 'pred-incorrect')}`; |
| 53 | pred.innerText = `pred: ${prediction}`; |
| 54 | |
| 55 | div.appendChild(pred); |
| 56 | div.appendChild(canvas); |
| 57 | |
| 58 | imagesElement.appendChild(div); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | const lossLabelElement = document.getElementById('loss-label'); |
| 63 | const accuracyLabelElement = document.getElementById('accuracy-label'); |