lmoroney / dlaicourse

Notebooks for learning deep learning
5.66k stars 5.36k forks source link

Incorrect Convolution Multiplication in Course 1 - Part 6 - Lesson 3 - Notebook.ipynb #66

Open kavita-srinivasan opened 4 years ago

kavita-srinivasan commented 4 years ago

The convolution multiplication statement looks like this:

convolution = convolution + (i[x, y-1] * filter[0][1])

i[x, y-1] is the pixel horizontally to the left of the center:

Screen Shot 2020-03-19 at 12 30 34 AM

The corresponding filter value should be filter[1][0], which is horizontally left of the center:

Screen Shot 2020-03-19 at 12 28 48 AM

In light of this, that code block should be changed to the following:

convolution = 0.0
convolution = convolution + (i[x - 1][y - 1] * filter[0][0])
convolution = convolution + (i[x - 1][y    ] * filter[0][1])
convolution = convolution + (i[x - 1][y + 1] * filter[0][2])
convolution = convolution + (i[x    ][y - 1] * filter[1][0])
convolution = convolution + (i[x    ][y    ] * filter[1][1])
convolution = convolution + (i[x    ][y + 1] * filter[1][2])
convolution = convolution + (i[x + 1][y - 1] * filter[2][0])
convolution = convolution + (i[x + 1][y    ] * filter[2][1])
convolution = convolution + (i[x + 1][y + 1] * filter[2][2])
convolution = convolution * weight
coyotegil commented 3 years ago

Dear Kavita, I guess your are right about this error on the convolution multiplication statement. I searched the forums on Coursera to see if someone else also spotted this but it's to crowed and I didn't manage to find any reference to this error.

I saw that there was something funny happening with the code because the filter that was supposed to highlight the vertical lines (filter = [ [-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) was actually highlighting the horizontal lines and vice-versa.

Thanks for sharing this correction.