0% found this document useful (0 votes)
79 views7 pages

NN Convtranspose1d

ConvTranspose1d is essentially an expanding convolution, while Conv1d is essentially a shrinking convolution. The nn.ConvTranspose1d layer was initialized with in_channels of 4, out_channels of 2, kernel_size of 3, stride of 2, and no output padding or bias. The weight parameter was then set manually and the layer was run on some sample input data to produce an output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views7 pages

NN Convtranspose1d

ConvTranspose1d is essentially an expanding convolution, while Conv1d is essentially a shrinking convolution. The nn.ConvTranspose1d layer was initialized with in_channels of 4, out_channels of 2, kernel_size of 3, stride of 2, and no output padding or bias. The weight parameter was then set manually and the layer was run on some sample input data to produce an output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

ConvTranspose1d 本質是擴增

Conv1d 本質是縮減
Only 2D, 3D, 4D, 5D padding with non-constant padding are supported for now
nn.ConvTranspose1d(in_channels = 7, out_channels = 6, kernel_size=10,
stride=2, output_padding=0, bias=False)
// torch.Size([ in_channels , out_channels, kernel_size ])
// torch.Size([7, 6, 10])

Output of print

--------------------------------------------------------------------------------------------
372 = 6* 1 + 100* 3 + 6* 1 + 6*10

import torch.nn as nn
import torch

m = nn.ConvTranspose1d(4, 2, kernel_size=3,
stride=2, output_padding=0, bias=False)

print(m.weight.shape)

para = torch.tensor([ [[ 6.0, 1.0, 2.0],


[ 3.0, 2.0, 1.0]],

[[ 100.0, 1.0, 0.0],


[ 3.0, 1.0, 0.0]],

[[ 6.0, 1.0, 2.0],


[ 3.0, 2.0, 1.0]],

[[ 6.0, 1.0, 2.0],


[ 3.0, 2.0, 1.0]] ])

m.weight = nn.Parameter(para)
data = torch.tensor([ [1.0, 1.0, 2.0, 0.0, 3.0],
[3.0, 0.0, 0.0, 1.0, 2.0],
[1.0, 1.0, 2.0, 0.0, 3.0],
[10.0, 1.0, 2.0, 0.0, 3.0] ])

print(m(data))
print(m(data).shape)

-----------------------------------------------------------------------------------------
測輸出 dim 用
import torch.nn as nn
import torch

m = nn.ConvTranspose1d(2, 5, kernel_size=3,
stride=2, output_padding=0, bias=False)

data = torch.tensor([ [1.0, 1.0, 2.0,7.0],


[3.0, 0.0, 0.0,0.0] ])

print(m(data).shape)
print(m(data))

You might also like