简体   繁体   中英

How to convert Conv1d into Conv2d? [PyTorch]

Is it possible with PyTorch to use Conv2d to perform a Conv1d ? The question may seem weird, but I need to use a tool that is not compatible with conv1d , but it works with conv2d .

What if I have Conv1d(in,out, kernel_size=3, stride=stride, padding=1, bias=False) ? May unsqueeze help me?

I have the same problem with AvgPool1d (-> AvgPool2d) and MaxPool1d (-> MaxPool2d) .

A Conv2D is mostly a generalized version of Conv1D. You can of course use a degenerate version of Conv2D to reproduce a 1D convolution - You'll need to add in another dimension to the data:

data_pnt = data_pnt [..., numpy.newaxis]

You'll also need to specify the kernel size - You'll be choosing a 1D kernel - for example:

Conv2d(in,out, kernel_size=(3,1), <Other Parameters>)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM