# Custom nn.Conv2d

**URL:** <https://discuss.pytorch.org/t/custom-nn-conv2d/62068>\
**Category:** autograd\
**Created:** [November 25, 2019, 6:36am UTC](https://discuss.pytorch.org/t/custom-nn-conv2d/62068 "2019-11-25T06:36:29Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![zahra](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/z/aeb1de/32.png) [@zahra](https://discuss.pytorch.org/u/zahra)\
**Post date:** [November 25, 2019, 8:51am UTC](https://discuss.pytorch.org/t/custom-nn-conv2d/62068/5 "2019-11-25T08:51:37Z")

</div>

Dear Sami,

Mentioned link “[Custom a new convolution layer in cnn](https://discuss.pytorch.org/t/custom-a-new-convolution-layer-in-cnn/43682/2)” is useful but it is just about forward pass of convolution layer. Backward pass have its own problems. For example, you should manage the dimension of produced gradient in your evaluations.

I suggest you to use Pytorch functions. Since Convolution is equivalent with Unfold + Matrix Multiplication + Fold maybe what ptrblck recommended you would be more useful and simpler.

I mean that whatever you can use ready Pytorch functions and I think most of the time there is a way instead of customizing layers.

If you want to customize a layer, I suggest you to check the open source implementation of multi-layer perceptron and convolution layer and their theories. Also, these two tutorials could help you:

[https://pytorch.org/tutorials/advanced/numpy\_extensions\_tutorial.html](https://pytorch.org/tutorials/advanced/numpy_extensions_tutorial.html)

[https://towardsdatascience.com/only-numpy-understanding-back-propagation-for-transpose-convolution-in-multi-layer-cnn-with-c0a07d191981](https://towardsdatascience.com/only-numpy-understanding-back-propagation-for-transpose-convolution-in-multi-layer-cnn-with-c0a07d191981)

Of course, what ptrblck sayes is more professional than mine.

Good luck

---

_[View the full topic](https://discuss.pytorch.org/t/custom-nn-conv2d/62068)._
