From d877ada2edf37b630169d22d7f30605d06676ae4 Mon Sep 17 00:00:00 2001 From: AdrianAlan Date: Thu, 20 Jul 2023 16:31:04 +0200 Subject: [PATCH] Bugfixes and solutions --- part3/2023-CoDaS-HEP-Exercises-3.ipynb | 29 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/part3/2023-CoDaS-HEP-Exercises-3.ipynb b/part3/2023-CoDaS-HEP-Exercises-3.ipynb index c0972a1..1b7a885 100644 --- a/part3/2023-CoDaS-HEP-Exercises-3.ipynb +++ b/part3/2023-CoDaS-HEP-Exercises-3.ipynb @@ -100,12 +100,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "3c5b8b78", "metadata": {}, - "outputs": [], - "source": [ - "def convolution(img, kernel, stride=None, padding=None):\n", + "outputs": [ + { + "ename": "IndentationError", + "evalue": "unindent does not match any outer indentation level (, line 7)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m File \u001b[0;32m:7\u001b[0;36m\u001b[0m\n\u001b[0;31m H = img.shape[0] # height of the image\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m unindent does not match any outer indentation level\n" + ] + } + ], + "source": [ + "def convolution(img, kernel, stride=None, padding=True):\n", + "\n", + " # Implement padding\n", + "# if padding:\n", + "# img = np.pad(img, 1, 'constant', constant_values=0)\n", " \n", " H = img.shape[0] # height of the image\n", " W = img.shape[1] # width of the image\n", @@ -115,12 +128,12 @@ " filt_h = kernel.shape[1]\n", " \n", " # In our case we only have one filer, so n=1. We will drop the 3rd dim for simplicity\n", - " img_out = np.zeros((H+1,W+1))\n", + " img_out = np.zeros((H-(S-1), W-(S-1)))\n", "\n", " # Nested loops over V and U\n", - " for v in range(S//2, H-S//2):\n", - " for u in range(S//2, W-S//2):\n", - " img_out[v, u] = np.sum(img[v-S//2:v+S//2+1,u-S//2:u+S//2+1]*kernel)\n", + " for v in range(0, H-(S-1)):\n", + " for u in range(0, W-(S-1)):\n", + " img_out[v, u] = np.sum(img[v:v+S, u:u+S] * kernel)\n", " return img_out" ] },