简体   繁体   English

如何将 Conv1d 转换为 Conv2d? [PyTorch]

[英]How to convert Conv1d into Conv2d? [PyTorch]

Is it possible with PyTorch to use Conv2d to perform a Conv1d ? PyTorch是否可以使用Conv2d来执行Conv1d The question may seem weird, but I need to use a tool that is not compatible with conv1d , but it works with conv2d .这个问题可能看起来很奇怪,但我需要使用与conv1d不兼容的工具,但它适用于conv2d

What if I have Conv1d(in,out, kernel_size=3, stride=stride, padding=1, bias=False) ?如果我有Conv1d(in,out, kernel_size=3, stride=stride, padding=1, bias=False)怎么办? May unsqueeze help me? unsqueeze 可以帮助我吗?

I have the same problem with AvgPool1d (-> AvgPool2d) and MaxPool1d (-> MaxPool2d) .我对AvgPool1d (-> AvgPool2d) and MaxPool1d (-> MaxPool2d)有同样的问题。

A Conv2D is mostly a generalized version of Conv1D. Conv2D 主要是 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:您当然可以使用 Conv2D 的退化版本来重现一维卷积 - 您需要向数据添加另一个维度:

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>)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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