Last active
August 25, 2024 07:06
-
-
Save wuriyanto48/f1eee5680341a50aa97fc9398637841e to your computer and use it in GitHub Desktop.
Pixel Size formula Conv Neural Network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calcOut(wh, padding, kernelSize, stride) { | |
return ((wh + 2*padding - kernelSize ) / stride) + 1; | |
} | |
// for image file 32x32 pixels | |
console.log(calcOut(32, 1, 3, 1)); // conv1 = 32 | |
console.log(calcOut(32, 1, 3, 1)); // conv2 = 32 | |
console.log(calcOut(32, 0, 2, 2)); // maxpool1 = 16 | |
console.log(16*16*32); // flattening result = 8192 | |
console.log("----------------"); | |
// for image file 28x28 pixels | |
console.log(calcOut(28, 1, 3, 1)); // conv1 = 28 | |
console.log(calcOut(28, 0, 2, 2)); // maxpool1 = 14 | |
console.log(calcOut(14, 1, 3, 1)); // conv2 = 14 | |
console.log(calcOut(14, 0, 2, 2)); // maxpool2 = 7 | |
console.log(7*7*64); // flattening result = 3136 | |
console.log("----------------"); | |
// for image file 28x28 pixels | |
console.log(calcOut(28, 0, 5, 1)); | |
console.log(calcOut(24, 0, 2, 2)); | |
console.log(calcOut(12, 0, 5, 1)); | |
console.log(calcOut(8, 0, 2, 2)); | |
console.log("----------------"); | |
// for image file 28x28 pixels | |
console.log(calcOut(28, 0, 5, 1)); // conv1 = 24 | |
console.log(calcOut(24, 0, 2, 2)); // maxpool1 = 12 | |
console.log(calcOut(12, 0, 5, 1)); // conv2 = 8 | |
console.log(calcOut(8, 0, 2, 2)); // maxpool2 = 4 | |
// 64 = batch size | |
// 20 = the number of channels | |
// 4 = width and height of the last output from maxpool2 | |
console.log(64*4*4*20); // 20480 | |
console.log(20480/64); // 320 | |
console.log("----------------"); |
Author
wuriyanto48
commented
Aug 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment