| 31 | } |
| 32 | |
| 33 | async function run() { |
| 34 | // Empty the image-and-result section. |
| 35 | while (imageResultSection.firstChild) { |
| 36 | imageResultSection.removeChild(imageResultSection.firstChild); |
| 37 | } |
| 38 | // Empty the viz section. |
| 39 | while (vizSection.firstChild) { |
| 40 | vizSection.removeChild(vizSection.firstChild); |
| 41 | } |
| 42 | |
| 43 | const activationManifest = |
| 44 | await (await fetch('activation/activation-manifest.json')).json(); |
| 45 | const filterManifest = |
| 46 | await (await fetch('filters/filters-manifest.json')).json(); |
| 47 | |
| 48 | // Render the input image in the image-result section. |
| 49 | const inputImage = document.createElement('img'); |
| 50 | inputImage.classList.add('input-image'); |
| 51 | inputImage.src = normalizePath(activationManifest.origImagePath); |
| 52 | imageResultSection.appendChild(inputImage); |
| 53 | |
| 54 | // Render the top-3 classification results. |
| 55 | for (let i = 0; i < 3; ++i) { |
| 56 | const outputClassDiv = document.createElement('div'); |
| 57 | outputClassDiv.textContent = `${activationManifest.classNames[i]} ` + |
| 58 | `(p=${activationManifest.probScores[i].toFixed(4)})`; |
| 59 | imageResultSection.appendChild(outputClassDiv); |
| 60 | } |
| 61 | |
| 62 | const vizType = vizTypeSelect.value; |
| 63 | |
| 64 | if (vizType === 'activation') { |
| 65 | const layerNames = Object.keys(activationManifest.layerName2FilePaths); |
| 66 | layerNames.sort(); |
| 67 | for (let i = 0; i < layerNames.length; ++i) { |
| 68 | const layerName = layerNames[i]; |
| 69 | const filePaths = activationManifest.layerName2FilePaths[layerName]; |
| 70 | |
| 71 | const layerDiv = document.createElement('div'); |
| 72 | layerDiv.classList.add('layer-div'); |
| 73 | const layerNameSpan = document.createElement('div'); |
| 74 | const height = activationManifest.layerName2ImageDims[layerName][0]; |
| 75 | const width = activationManifest.layerName2ImageDims[layerName][1]; |
| 76 | layerNameSpan.textContent = `Layer "${layerName}" (${height}x${width})`; |
| 77 | layerDiv.appendChild(layerNameSpan); |
| 78 | |
| 79 | const layerFiltersDiv = document.createElement('div'); |
| 80 | layerFiltersDiv.classList.add('layer-filters'); |
| 81 | for (let j = 0; j < filePaths.length; ++j) { |
| 82 | const filterDiv = document.createElement('div'); |
| 83 | filterDiv.classList.add('filter-div'); |
| 84 | const activationImg = document.createElement('img'); |
| 85 | activationImg.classList.add('activation-image'); |
| 86 | activationImg.src = normalizePath(filePaths[j]); |
| 87 | filterDiv.appendChild(activationImg); |
| 88 | layerFiltersDiv.appendChild(filterDiv); |
| 89 | } |
| 90 | layerDiv.appendChild(layerFiltersDiv); |