# How to define a deconvolution layer?

**URL:** <https://discuss.pytorch.org/t/how-to-define-a-deconvolution-layer/5767>\
**Category:** Uncategorized\
**Created:** [August 4, 2017, 2:34am UTC](https://discuss.pytorch.org/t/how-to-define-a-deconvolution-layer/5767 "2017-08-04T02:34:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EsamOthman](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/e/0ea827/32.png) [@EsamOthman](https://discuss.pytorch.org/u/EsamOthman)\
**Post date:** [August 4, 2017, 2:34am UTC](https://discuss.pytorch.org/t/how-to-define-a-deconvolution-layer/5767/1 "2017-08-04T02:34:30Z")

</div>

Hii

I’m new in pytorch, any help will be appreciated.  
I want to use deconvolution to estimate an image for 1-D feature. The same as DWT (discrete wavelet transform).

Thnx

---

<div class="post-metadata">

**Author:** ![Jing](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jing/32/3982_2.png) [@Jing](https://discuss.pytorch.org/u/Jing)\
**Post date:** [August 4, 2017, 4:02am UTC](https://discuss.pytorch.org/t/how-to-define-a-deconvolution-layer/5767/2 "2017-08-04T04:02:33Z")

</div>

`torch.nn.ConvTranspose2d` can do unsampling and can be regarded as a deconvolution operation.

---

<div class="post-metadata">

**Author:** ![EsamOthman](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/e/0ea827/32.png) [@EsamOthman](https://discuss.pytorch.org/u/EsamOthman)\
**Post date:** [August 4, 2017, 11:38pm UTC](https://discuss.pytorch.org/t/how-to-define-a-deconvolution-layer/5767/3 "2017-08-04T23:38:40Z")

</div>

Thnx for reply

I tried modifying this code but it gives me error.

```
    self.layer1 = nn.Sequential(
        nn.Conv2d(1, 16, kernel_size=5, padding=2),
        nn.BatchNorm2d(16),
        nn.ReLU(),
        nn.MaxPool2d(2))

```

Kindly, can u modify this code so it can be used for deconvolution?

---

<div class="post-metadata">

**Author:** ![Brando\_Miranda](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/brando_miranda/32/14355_2.png) [@Brando\_Miranda](https://discuss.pytorch.org/u/Brando_Miranda)\
**Post date:** [July 28, 2019, 3:56am UTC](https://discuss.pytorch.org/t/how-to-define-a-deconvolution-layer/5767/4 "2019-07-28T03:56:57Z")

</div>

do you have a code example?
