-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
513 lines (431 loc) · 24.6 KB
/
script.js
File metadata and controls
513 lines (431 loc) · 24.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
document.addEventListener('DOMContentLoaded', function() {
// Initialize matrices with default values
let inputMatrix = [];
let weightMatrix = [];
let outputMatrix = [];
let paddedInputMatrix = [];
// Animation variables
let animationInterval = null;
let currentStep = 0;
let animationSpeed = 500; // milliseconds
// MNIST 28x28 grayscale image data representing the digit "5"
// Values are actual pixel intensities (0-255) creating a recognizable digit pattern
const mnistImageData = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 30, 60, 120, 180, 220, 255, 255, 255, 255, 255, 255, 255, 255, 220, 180, 120, 60, 30, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 50, 120, 200, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 200, 120, 50, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 70, 150, 220, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 220, 150, 70, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 80, 160, 230, 255, 255, 255, 200, 120, 80, 40, 20, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 90, 170, 240, 255, 255, 200, 100, 50, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 100, 180, 250, 255, 180, 80, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 110, 190, 255, 200, 80, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 120, 200, 255, 150, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 130, 210, 255, 200, 140, 100, 80, 60, 40, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 140, 220, 255, 255, 255, 255, 255, 255, 255, 240, 180, 120, 60, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 150, 230, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 240, 180, 120, 60, 30, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 160, 240, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 240, 180, 120, 60, 30, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 40, 80, 120, 160, 200, 240, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 240, 180, 120, 60, 30, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 20, 60, 120, 180, 220, 255, 255, 255, 255, 255, 255, 255, 255, 255, 240, 180, 120, 60, 30, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 60, 120, 180, 220, 255, 255, 255, 255, 255, 255, 255, 240, 180, 120, 60, 30],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 60, 120, 180, 220, 255, 255, 255, 255, 255, 255, 240, 180, 120, 60],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 60, 120, 180, 220, 255, 255, 255, 255, 255, 240, 180, 120],
[0, 0, 0, 0, 30, 60, 120, 180, 220, 255, 200, 140, 80, 40, 20, 40, 80, 140, 200, 255, 255, 255, 255, 255, 240, 180, 120, 60],
[0, 0, 0, 0, 50, 120, 200, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 240, 180, 120, 60, 30],
[0, 0, 0, 0, 70, 150, 220, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 240, 180, 120, 60, 30, 0],
[0, 0, 0, 0, 80, 160, 230, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 240, 180, 120, 60, 30, 0, 0, 0, 0],
[0, 0, 0, 0, 30, 60, 120, 180, 220, 255, 255, 255, 255, 255, 255, 240, 180, 120, 60, 30, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
];
// Get DOM elements
const inputHeightEl = document.getElementById('input-height');
const inputWidthEl = document.getElementById('input-width');
const kernelHeightEl = document.getElementById('kernel-height');
const kernelWidthEl = document.getElementById('kernel-width');
const paddingEl = document.getElementById('padding');
const dilationEl = document.getElementById('dilation');
const strideEl = document.getElementById('stride');
const inputTypeEl = document.getElementById('input-type');
const updateBtn = document.getElementById('update-btn');
const animateBtn = document.getElementById('animate-btn');
const stopBtn = document.getElementById('stop-btn');
const speedEl = document.getElementById('speed');
const inputMatrixEl = document.getElementById('input-matrix');
const weightMatrixEl = document.getElementById('weight-matrix');
const outputMatrixEl = document.getElementById('output-matrix');
const inputDimEl = document.getElementById('input-dim');
const kernelDimEl = document.getElementById('kernel-dim');
const outputDimEl = document.getElementById('output-dim');
// Update visualization on button click
updateBtn.addEventListener('click', updateVisualization);
// Initialize with default values
updateVisualization();
// Animation controls
animateBtn.addEventListener('click', startAnimation);
stopBtn.addEventListener('click', stopAnimation);
speedEl.addEventListener('input', updateAnimationSpeed);
function updateAnimationSpeed() {
// Convert slider value (1-10) to milliseconds (1000-100)
animationSpeed = 1100 - (speedEl.value * 100);
if (animationInterval) {
stopAnimation();
startAnimation();
}
}
function startAnimation() {
if (animationInterval) {
stopAnimation();
}
currentStep = 0;
resetHighlights();
animationInterval = setInterval(animateStep, animationSpeed);
}
function stopAnimation() {
if (animationInterval) {
clearInterval(animationInterval);
animationInterval = null;
}
resetHighlights();
}
function animateStep() {
const inputHeight = parseInt(inputHeightEl.value);
const inputWidth = parseInt(inputWidthEl.value);
const kernelHeight = parseInt(kernelHeightEl.value);
const kernelWidth = parseInt(kernelWidthEl.value);
const padding = parseInt(paddingEl.value);
const dilation = parseInt(dilationEl.value);
const stride = parseInt(strideEl.value);
// Calculate output dimensions
const effectiveKernelHeight = kernelHeight + (kernelHeight - 1) * (dilation - 1);
const effectiveKernelWidth = kernelWidth + (kernelWidth - 1) * (dilation - 1);
const outputHeight = Math.floor((inputHeight + 2 * padding - effectiveKernelHeight) / stride) + 1;
const outputWidth = Math.floor((inputWidth + 2 * padding - effectiveKernelWidth) / stride) + 1;
// Calculate the current position
const totalSteps = outputHeight * outputWidth;
if (currentStep >= totalSteps) {
stopAnimation();
return;
}
// Calculate row and column in output matrix
const outputRow = Math.floor(currentStep / outputWidth);
const outputCol = currentStep % outputWidth;
// Highlight relevant cells for this step
resetHighlights();
// Highlight the current output cell
const outputCellId = `output-${outputRow}-${outputCol}`;
const outputCell = document.getElementById(outputCellId);
if (outputCell) {
outputCell.classList.add('output-highlight');
}
// Highlight the corresponding input region
const inputStartRow = outputRow * stride - padding;
const inputStartCol = outputCol * stride - padding;
for (let kh = 0; kh < kernelHeight; kh++) {
for (let kw = 0; kw < kernelWidth; kw++) {
const inputRow = inputStartRow + kh * dilation;
const inputCol = inputStartCol + kw * dilation;
// Check if this is a valid input position (not padding)
if (inputRow >= 0 && inputRow < inputHeight && inputCol >= 0 && inputCol < inputWidth) {
const inputCellId = `input-${inputRow}-${inputCol}`;
const inputCell = document.getElementById(inputCellId);
if (inputCell) {
inputCell.classList.add('input-highlight');
}
}
// Always highlight the weight cell
const weightCellId = `weight-${kh}-${kw}`;
const weightCell = document.getElementById(weightCellId);
if (weightCell) {
weightCell.classList.add('weight-highlight');
}
}
}
currentStep++;
}
function resetHighlights() {
// Remove all highlights
document.querySelectorAll('.input-highlight, .weight-highlight, .output-highlight').forEach(el => {
el.classList.remove('input-highlight', 'weight-highlight', 'output-highlight');
});
}
function updateVisualization() {
// Get parameters
const inputHeight = parseInt(inputHeightEl.value);
const inputWidth = parseInt(inputWidthEl.value);
const kernelHeight = parseInt(kernelHeightEl.value);
const kernelWidth = parseInt(kernelWidthEl.value);
const padding = parseInt(paddingEl.value);
const dilation = parseInt(dilationEl.value);
const stride = parseInt(strideEl.value);
// Update dimension labels
inputDimEl.textContent = `${inputHeight} × ${inputWidth}`;
kernelDimEl.textContent = `${kernelHeight} × ${kernelWidth}`;
// Calculate output dimensions
const effectiveKernelHeight = kernelHeight + (kernelHeight - 1) * (dilation - 1);
const effectiveKernelWidth = kernelWidth + (kernelWidth - 1) * (dilation - 1);
const outputHeight = Math.floor((inputHeight + 2 * padding - effectiveKernelHeight) / stride) + 1;
const outputWidth = Math.floor((inputWidth + 2 * padding - effectiveKernelWidth) / stride) + 1;
outputDimEl.textContent = `${outputHeight} × ${outputWidth}`;
// Generate random matrices
generateMatrices(inputHeight, inputWidth, kernelHeight, kernelWidth, padding, outputHeight, outputWidth);
// Render the matrices
renderMatrix(paddedInputMatrix, inputMatrixEl, 'input', padding, inputHeight, inputWidth);
renderMatrix(weightMatrix, weightMatrixEl, 'weight');
renderMatrix(outputMatrix, outputMatrixEl, 'output');
// Add event listeners for interactivity
addInteractivity();
}
function generateMatrices(inputHeight, inputWidth, kernelHeight, kernelWidth, padding, outputHeight, outputWidth) {
const inputType = inputTypeEl.value;
if (inputType === 'image') {
// Generate input matrix from MNIST image data (no normalization)
inputMatrix = Array(inputHeight).fill().map((_, i) =>
Array(inputWidth).fill().map((_, j) => {
// Map to image data coordinates
const imgRow = Math.floor((i / inputHeight) * mnistImageData.length);
const imgCol = Math.floor((j / inputWidth) * mnistImageData[0].length);
const pixelValue = mnistImageData[imgRow][imgCol];
// Return actual pixel values (0-255) without normalization
return pixelValue;
})
);
} else {
// Generate input matrix with random values (0-9)
inputMatrix = Array(inputHeight).fill().map(() =>
Array(inputWidth).fill().map(() => Math.floor(Math.random() * 10))
);
}
// Generate weight matrix with random values (-2 to 2)
weightMatrix = Array(kernelHeight).fill().map(() =>
Array(kernelWidth).fill().map(() => Math.floor(Math.random() * 5) - 2)
);
// Create padded input matrix
paddedInputMatrix = Array(inputHeight + 2 * padding).fill().map((_, i) =>
Array(inputWidth + 2 * padding).fill().map((_, j) => {
const r = i - padding;
const c = j - padding;
if (r >= 0 && r < inputHeight && c >= 0 && c < inputWidth) {
return inputMatrix[r][c];
}
return 0; // Padding value
})
);
// Calculate output matrix
calculateOutputMatrix(padding, outputHeight, outputWidth);
}
function calculateOutputMatrix(padding, outputHeight, outputWidth) {
const kernelHeight = weightMatrix.length;
const kernelWidth = weightMatrix[0].length;
const dilation = parseInt(dilationEl.value);
const stride = parseInt(strideEl.value);
outputMatrix = Array(outputHeight).fill().map((_, oh) =>
Array(outputWidth).fill().map((_, ow) => {
let sum = 0;
for (let kh = 0; kh < kernelHeight; kh++) {
for (let kw = 0; kw < kernelWidth; kw++) {
const ih = oh * stride + kh * dilation;
const iw = ow * stride + kw * dilation;
sum += paddedInputMatrix[ih][iw] * weightMatrix[kh][kw];
}
}
return sum;
})
);
}
function renderMatrix(matrix, container, type, padding = 0, inputHeight = 0, inputWidth = 0) {
container.innerHTML = '';
const inputType = inputTypeEl.value;
// Determine cell size based on matrix size and type
let cellSize = 40;
if (type === 'input' && inputType === 'image' && inputHeight >= 20) {
cellSize = Math.max(15, Math.min(25, 600 / Math.max(inputHeight, inputWidth)));
}
// Set grid dimensions
container.style.gridTemplateRows = `repeat(${matrix.length}, ${cellSize}px)`;
container.style.gridTemplateColumns = `repeat(${matrix[0].length}, ${cellSize}px)`;
for (let i = 0; i < matrix.length; i++) {
for (let j = 0; j < matrix[i].length; j++) {
const cell = document.createElement('div');
cell.className = 'cell';
cell.id = `${type}-${i}-${j}`;
// Apply dynamic sizing for image cells
if (type === 'input' && inputType === 'image' && inputHeight >= 20) {
cell.style.width = `${cellSize}px`;
cell.style.height = `${cellSize}px`;
cell.style.fontSize = `${Math.max(8, cellSize * 0.4)}px`;
}
// Check if this is a padding cell for the input matrix
if (type === 'input' && (i < padding || i >= inputHeight + padding || j < padding || j >= inputWidth + padding)) {
cell.classList.add('padding-cell');
} else {
cell.classList.add(`${type}-cell`);
// Add image background for input cells when using image input
if (type === 'input' && inputType === 'image' && !(i < padding || i >= inputHeight + padding || j < padding || j >= inputWidth + padding)) {
cell.classList.add('image-cell');
// Calculate the corresponding image pixel
const actualRow = i - padding;
const actualCol = j - padding;
const imgRow = Math.floor((actualRow / inputHeight) * mnistImageData.length);
const imgCol = Math.floor((actualCol / inputWidth) * mnistImageData[0].length);
const pixelValue = mnistImageData[imgRow][imgCol];
// Set background color based on pixel value (grayscale)
cell.style.backgroundColor = `rgb(${pixelValue}, ${pixelValue}, ${pixelValue})`;
}
// Add image-based background for output cells when using image input
if (type === 'output' && inputType === 'image') {
cell.classList.add('image-cell');
// Map output value to a color intensity
// Find min/max values in the output matrix for normalization
const flatOutput = outputMatrix.flat();
const minOutput = Math.min(...flatOutput);
const maxOutput = Math.max(...flatOutput);
const outputValue = matrix[i][j];
// Normalize output value to 0-255 range for visualization
let normalizedValue;
if (maxOutput !== minOutput) {
normalizedValue = Math.round(((outputValue - minOutput) / (maxOutput - minOutput)) * 255);
} else {
normalizedValue = 128; // Middle gray if all values are the same
}
// Apply a blue-to-red colormap for better visualization of positive/negative values
let red, green, blue;
if (outputValue < 0) {
// Negative values: blue tones
const intensity = Math.abs(outputValue - minOutput) / Math.abs(minOutput) * 255;
red = Math.max(0, 255 - intensity);
green = Math.max(0, 255 - intensity);
blue = 255;
} else {
// Positive values: red tones
const intensity = (outputValue / maxOutput) * 255;
red = 255;
green = Math.max(0, 255 - intensity);
blue = Math.max(0, 255 - intensity);
}
// Set background color with transparency to show the pattern
cell.style.backgroundColor = `rgba(${red}, ${green}, ${blue}, 0.6)`;
}
}
// Use a span for the text content to ensure it's above the background
const textSpan = document.createElement('span');
textSpan.textContent = matrix[i][j];
cell.appendChild(textSpan);
container.appendChild(cell);
}
}
}
function addInteractivity() {
// Input cell hover - highlight corresponding output cells
const inputCells = document.querySelectorAll('.input-cell');
inputCells.forEach(cell => {
cell.addEventListener('mouseenter', () => highlightInputRelationships(cell));
cell.addEventListener('mouseleave', resetHighlights);
});
// Weight cell hover - highlight which inputs were used to compute outputs
const weightCells = document.querySelectorAll('.weight-cell');
weightCells.forEach(cell => {
cell.addEventListener('mouseenter', () => highlightWeightRelationships(cell));
cell.addEventListener('mouseleave', resetHighlights);
});
// Output cell hover - highlight corresponding input cells and weights
const outputCells = document.querySelectorAll('.output-cell');
outputCells.forEach(cell => {
cell.addEventListener('mouseenter', () => highlightOutputRelationships(cell));
cell.addEventListener('mouseleave', resetHighlights);
});
}
function highlightInputRelationships(cell) {
const [_, rowStr, colStr] = cell.id.split('-');
const row = parseInt(rowStr);
const col = parseInt(colStr);
const padding = parseInt(paddingEl.value);
const stride = parseInt(strideEl.value);
const dilation = parseInt(dilationEl.value);
const kernelHeight = weightMatrix.length;
const kernelWidth = weightMatrix[0].length;
const effectiveKernelHeight = kernelHeight + (kernelHeight - 1) * (dilation - 1);
const effectiveKernelWidth = kernelWidth + (kernelWidth - 1) * (dilation - 1);
// Check which output cells are affected by this input
for (let oh = 0; oh < outputMatrix.length; oh++) {
for (let ow = 0; ow < outputMatrix[0].length; ow++) {
// Calculate input region for this output
const inputStartRow = oh * stride;
const inputStartCol = ow * stride;
const inputEndRow = inputStartRow + effectiveKernelHeight - 1;
const inputEndCol = inputStartCol + effectiveKernelWidth - 1;
// Check if our input cell is within this region
if (row >= inputStartRow && row <= inputEndRow && col >= inputStartCol && col <= inputEndCol) {
// Check if it's actually used by the kernel (considering dilation)
if ((row - inputStartRow) % dilation === 0 && (col - inputStartCol) % dilation === 0) {
// This input cell affects this output cell
const outputCell = document.getElementById(`output-${oh}-${ow}`);
if (outputCell) {
outputCell.classList.add('output-highlight');
}
}
}
}
}
// Highlight the input cell
cell.classList.add('input-highlight');
}
function highlightWeightRelationships(cell) {
const [_, rowStr, colStr] = cell.id.split('-');
const kernelRow = parseInt(rowStr);
const kernelCol = parseInt(colStr);
const padding = parseInt(paddingEl.value);
const stride = parseInt(strideEl.value);
const dilation = parseInt(dilationEl.value);
// Highlight the weight cell
cell.classList.add('weight-highlight');
// For each output position, highlight the input position that uses this weight
for (let oh = 0; oh < outputMatrix.length; oh++) {
for (let ow = 0; ow < outputMatrix[0].length; ow++) {
const inputRow = oh * stride + kernelRow * dilation;
const inputCol = ow * stride + kernelCol * dilation;
// Highlight corresponding input cell
const inputCell = document.getElementById(`input-${inputRow}-${inputCol}`);
if (inputCell) {
inputCell.classList.add('input-highlight');
}
// Highlight corresponding output cell
const outputCell = document.getElementById(`output-${oh}-${ow}`);
if (outputCell) {
outputCell.classList.add('output-highlight');
}
}
}
}
function highlightOutputRelationships(cell) {
const [_, rowStr, colStr] = cell.id.split('-');
const row = parseInt(rowStr);
const col = parseInt(colStr);
const padding = parseInt(paddingEl.value);
const stride = parseInt(strideEl.value);
const dilation = parseInt(dilationEl.value);
const kernelHeight = weightMatrix.length;
const kernelWidth = weightMatrix[0].length;
// Highlight the output cell
cell.classList.add('output-highlight');
// Highlight corresponding input region and weights
for (let kh = 0; kh < kernelHeight; kh++) {
for (let kw = 0; kw < kernelWidth; kw++) {
// Highlight weight
const weightCell = document.getElementById(`weight-${kh}-${kw}`);
if (weightCell) {
weightCell.classList.add('weight-highlight');
}
// Highlight input
const inputRow = row * stride + kh * dilation;
const inputCol = col * stride + kw * dilation;
const inputCell = document.getElementById(`input-${inputRow}-${inputCol}`);
if (inputCell) {
inputCell.classList.add('input-highlight');
}
}
}
}
});