Key iteration counters are based on the output shape, Z.
So, what we need to adjust is an input side to set the start points (horiz, vert) to consider the stride.
What you did is to use this stride as a step for iteration counters. This is not correct. We need to keep the counter, which is the output shape, as is. What we need to do is to adjust vert_start and horiz_start (and vert_end and horiz_end correspondingly) with considering a stride.
Hope this helps.
And, as Balaji suggested, please remove your code.
I updated the figure. (n_W and n_H were not set correctly).
This is what i am asking. How to set the vert_start, vert_end, horiz_start and horiz_end. I nowhere found any formula for the same in the lectures.
That’s not a matter of formula, but an algorithm that you need to implement.
And, this is an important convolutional step that we need to learn through this exercise.
(Actually, this algorithm is hidden under Tensorflow/Keras API like Conv2D, but this is a good exercise to learn what Conv2D is doing.)
I think the above figure shows what a convolution is doing, and what you need to implement. If you still have an issue, please elaborate.
What you did is to use this stride as a step for iteration counters. This is not correct. We need to keep the counter, which is the output shape, as is. What we need to do is to adjust vert_start and horiz_start (and vert_end and horiz_end correspondingly) with considering a stride.
You need to fix
“range” for iterations for h and w. No need to set “stride” in here, since, as I wrote, its counter is based on output size. Need a continuous index.
horiz_start/vert_start. Now you have a correct counter h, w. You need to consider the stride in here to set the correct position. That is also in my figure.
horiz_end/vert-end. It is quite easy. Just add a filter size (f), to the start points.
You can see several layers in there, since both convolutional_block and identify_block include multiple layers in there.
By the way, if you start to talk about a different assignment, then, it is better to create a new topics so that others can easily search relevant topics.