Skip to content

Commit

Permalink
Bugfixes and solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianAlan committed Jul 20, 2023
1 parent fb2df2f commit d877ada
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions part3/2023-CoDaS-HEP-Exercises-3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<tokenize>, line 7)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m<tokenize>: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",
Expand All @@ -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"
]
},
Expand Down

0 comments on commit d877ada

Please sign in to comment.