Skip to content

Commit 7cc03fd

Browse files
committed
corrected convolution channel count
1 parent 91b97d5 commit 7cc03fd

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

notebooks/kernels.ipynb

+9-8
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"source": [
5757
"def conv2d(X, W, pad=1, stride=1):\n",
5858
" # filter\\kernel size\n",
59-
" f, f, n_C = W.shape\n",
59+
" f, f, _ = W.shape\n",
60+
" n_C = 1\n",
6061
" \n",
6162
" # new output volume\n",
6263
" n_H = int(np.floor(X.shape[0] - f + 2 * pad) / (stride * 1.)) + 1\n",
@@ -83,7 +84,7 @@
8384
"metadata": {},
8485
"source": [
8586
"# Max Pooling\n",
86-
"Size reduction via max pooling!"
87+
"Implements max pooling with the given pool size and stride."
8788
]
8889
},
8990
{
@@ -94,8 +95,8 @@
9495
"source": [
9596
"def max_pooling2d(X, pool_size=2, stride=2):\n",
9697
" # new output volume\n",
97-
" n_H = int(np.floor(X.shape[0] - pool_size + 2) / (stride * 1.)) #+ 1\n",
98-
" n_W = int(np.floor(X.shape[1] - pool_size + 2) / (stride * 1.)) #+ 1\n",
98+
" n_H = int(np.floor(X.shape[0] - pool_size) / (stride * 1.)) + 1\n",
99+
" n_W = int(np.floor(X.shape[1] - pool_size) / (stride * 1.)) + 1\n",
99100
" n_C = X.shape[2]\n",
100101
" \n",
101102
" Z = np.zeros((n_H, n_W, n_C))\n",
@@ -125,12 +126,12 @@
125126
"metadata": {},
126127
"outputs": [],
127128
"source": [
128-
"w = np.zeros((3, 3, 1))\n",
129+
"w = np.zeros((3, 3, 3))\n",
129130
"t = np.array([[1, 1, 1], [0, 0, 0], [-1, -1, -1]]) / 3\n",
130131
"#t = np.array([[0, 0, 0], [0, 1., 0], [0, 0, 0]]) / 3\n",
131132
"w[:,:,0] = t\n",
132-
"#w[:,:,1] = t\n",
133-
"#w[:,:,2] = t"
133+
"w[:,:,1] = t\n",
134+
"w[:,:,2] = t"
134135
]
135136
},
136137
{
@@ -147,7 +148,7 @@
147148
"metadata": {},
148149
"outputs": [],
149150
"source": [
150-
"image = np.array(open_and_resize(\"fence.jpg\", resize=(400,400)))\n",
151+
"image = np.array(open_and_resize(\"wedding.jpg\", resize=(400,400)))\n",
151152
"plt.imshow(image)"
152153
]
153154
},

0 commit comments

Comments
 (0)