Created
January 15, 2020 08:38
-
-
Save avmoldovan/c42262445bd6fb1ac2f6621474532f17 to your computer and use it in GitHub Desktop.
Naive Conv2D implementation
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
#from here https://gist.githubusercontent.com/anirudhshenoy/4d5e579d3585159f133ca7804cdca25a/raw/c7314527d27bc70ab38b061b5e33b086704252e0/conv_2d.py | |
def conv_2d(x, kernel, bias): | |
kernel_shape = kernel.shape[0] | |
# Assuming Padding = 0, stride = 1 | |
output_shape = x.shape[0] - kernel_shape + 1 | |
result = np.zeros((output_shape, output_shape)) | |
for row in range(x.shape[0] - 1): | |
for col in range(x.shape[1] - 1): | |
window = x[row: row + kernel_shape, col: col + kernel_shape] | |
result[row, col] = np.sum(np.multiply(kernel,window)) | |
return result + bias |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment