# 1D Convolution using 2D Convolution

**URL:** <https://discuss.pytorch.org/t/1d-convolution-using-2d-convolution/65048>\
**Category:** Uncategorized\
**Created:** [December 26, 2019, 10:49am UTC](https://discuss.pytorch.org/t/1d-convolution-using-2d-convolution/65048 "2019-12-26T10:49:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![antimora](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/antimora/32/17873_2.png) [@antimora](https://discuss.pytorch.org/u/antimora)\
**Post date:** [December 26, 2019, 10:49am UTC](https://discuss.pytorch.org/t/1d-convolution-using-2d-convolution/65048/1 "2019-12-26T10:49:22Z")

</div>

Here is a problem I am currently facing. I have a model that uses 1D convolution that I would like to export to ONNX and use pytorch/glow or tvm to compile. But both projects currently do not support 1D convolution (see [pytorch/glow/issues/3246](https://github.com/pytorch/glow/issues/3246) and [tvm/issues/4587](https://github.com/apache/incubator-tvm/issues/4587). A workaround that has been suggested ([see an example](https://github.com/apache/incubator-tvm/commit/aa4241390e870880392bf388883377e3367f03a8#diff-fe67a468a757f6154fb40a510fa3e521R67-R83)) is to use 2D Convolution with height 1 for 1D convolution

Has anyone done this before using PyTorch? The [PyTorch documentation for Conv2d](https://pytorch.org/docs/stable/nn.html#conv2d) suggests it would be possible to have “non-square kernels and unequal stride and with padding and dilation”. It seems I can have a wrapper class for Conv1d that uses Conv2d underneath. Is there any downside to it? Does math checks out? Also it looks like I have to do the same for BatchNorm1d and pooling.

---

<div class="post-metadata">

**Author:** ![JuanFMontesinos](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/juanfmontesinos/32/76115_2.png) [@JuanFMontesinos](https://discuss.pytorch.org/u/JuanFMontesinos)\
**Post date:** [December 26, 2019, 11:47am UTC](https://discuss.pytorch.org/t/1d-convolution-using-2d-convolution/65048/2 "2019-12-26T11:47:39Z")

</div>

Yes ofc. Think of a convolution as an sliding window. You can slide the kernel through a 1d signal right? You can think of a 2d convolution as an spatial kernel right? If one of the dimensions is 1 then it’s the same than a 1d convolution.  
In fact you can do a sanity check which is applying a 1d convolution and use its weights to emulate the same result with a 2d convolution.
