Posted in Python onJune 23, 2020
问题:如何经过convTransposed1d输出指定大小的特征?
import torch from torch import nn import torch.nn.functional as F conv1 = nn.Conv1d(1, 2, 3, padding=1) conv2 = nn.Conv1d(in_channels=2, out_channels=4, kernel_size=3, padding=1) #转置卷积 dconv1 = nn.ConvTranspose1d(4, 1, kernel_size=3, stride=2, padding=1, output_padding=1) x = torch.randn(16, 1, 8) print(x.size()) x1 = conv1(x) x2 = conv2(x1) print(x2.size()) x3 = dconv1(x2) print(x3.size()) ''' torch.Size([16, 1, 8]) torch.Size([16, 4, 8]) #conv2输出特征图大小 torch.Size([16, 1, 16]) #转置卷积输出特征图大小 '''
#转置卷积 dconv1 = nn.ConvTranspose1d(1, 1, kernel_size=3, stride=3, padding=1, output_padding=1) x = torch.randn(16, 1, 8) print(x.size()) #torch.Size([16, 1, 23]) x3 = dconv1(x) print(x3.size()) #torch.Size([16, 1, 23])
下面两图为演示conv1d,在padding和不padding下的输出特征图大小
不带padding
带padding
补充知识:判断pytorch是否支持GPU加速
如下所示:
print torch.cuda.is_available()
以上这篇pytorch 计算ConvTranspose1d输出特征大小方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。
pytorch 计算ConvTranspose1d输出特征大小方式
- Author -
明月几时有.声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@