There seem to be a few minor mistakes in the code:


h and w should probably de defined as input.size(2) and input.size(3), respectively.
Currently you are assigning the same input value to both. However, since you are passing input directly, they can also be removed completely.
As already mentioned, you are passing input, so I’m not sure what image should be used for.
You are also passing the weight to forward, which would make filt unnecessary. Also, you are currently re-initializing filt in each forward pass, which won’t store the already learned weights, so use weight instead for your operations.
Are you using the nested loop to compare the outputs of patches * filt or what is it used for?

patches.sum(1) calculates the sum over dim1. I’m currently not sure, which shape patches would have at that point.




 Sami_Hassan:

After that there is addition “patches = patches.sum(1)” i am not sure what is it doing , I would like to replace the addition as well.


How would you like to replace the addition?
Also, could you print the shape of patches before calculating sum(1) and name all dimensions, so that we can understand the use case better?