<jupyter_start><jupyter_text>Pytorch 입력의 형태* input type: torch.Tensor* input shape : `(batch_size, channel, height, width)`<jupyter_code>x = x.view(-1, 1, 4, 4)
x
x.shape<jupyter_output><empty_output><jupyter_text>Conv2d<jupyter_code>out = nn.Conv2d(1, 1, kernel_size = 3, stride = 1, padding = 1, bias = False)
nn.init.constant_(out.weight.data, 1) # initialize weights<jupyter_output><empty_output><jupyter_text>Convolution output size $$ Output\;Size = floor(\frac{Input\;Size - Kernel\;Size + (2*padding)}{Stride})+1 $$ input size= 4, filter size= 3, padding= 1, Stride= 1<jupyter_code>out(x)
out(x).shape<jupyter_output><empty_output><jupyter_text>input size= 4, filter size= 3, padding= 2, Stride= 1<jupyter_code>out.kernel_size = 3
out.padding = 2
out(x)
out(x).shape<jupyter_output><empty_output><jupyter_text>ConvTranspose2d- Refer to https://pytorch.org/docs/stable/generated/torch.nn.ConvTranspose2d.html `padding` controls the amount of implicit zero-paddings on both sides for `dilation * (kernel_size - 1) - padding` number of points. See note below for details. 위에서의 `padding`은 Transpose Conv를 위해 input에 추가로 들어가는 padding 수를 의미. 따라서 아래 nn.ConvTranspose2d와 같이 padding = 0로 정할 경우, padding = 1*(3-1)-0 = 2. Input Size(4X4->6X6) 결국 ConvTrnspose2d 또한 padding을 붙이는 방식만 위와 같이 한 Conv2d 계산을 함(dilation=1일 때)   Padding Check<jupyter_code>transpose = nn.ConvTranspose2d(in_channels=1, out_channels=1, kernel_size=2, stride=1, padding=0, output_padding=0, bias=False)
nn.init.constant_(transpose.weight.data,1)
nn.ZeroPad2d((1, 1, 1, 1))(x)
transpose(x)
transpose(x).shape
transpose = nn.ConvTranspose2d(in_channels=1, out_channels=1, kernel_size=2, stride=1, padding=1, output_padding=0, bias=False)
nn.init.constant_(transpose.weight.data,1)
nn.ZeroPad2d((0, 0, 0, 0))(x)
transpose(x)
transpose(x).shape<jupyter_output><empty_output><jupyter_text>refer to https://medium.com/apache-mxnet/transposed-convolutions-explained-with-ms-excel-52d13030c7e8    - 참고<jupyter_code>transpose = nn.ConvTranspose2d(in_channels=1, out_channels=1, kernel_size=3, stride=1, padding=0, output_padding=0, bias=False)
nn.init.constant_(transpose.weight.data,1)
nn.ZeroPad2d((2, 2, 2, 2))(x)<jupyter_output><empty_output><jupyter_text>input size= 4, filter size= 3, padding= 0, Stride= 1, output_padding = 0<jupyter_code>transpose(x)
transpose(x).shape<jupyter_output><empty_output><jupyter_text>input size= 4, filter size= 3, padding= 2(padding is zero), Stride= 1, output_padding = 0<jupyter_code>nn.ZeroPad2d((0, 0, 0, 0))(x)
transpose.output_padding = 0
transpose.padding = 2
transpose.stride = 1
transpose(x)
transpose(x).shape<jupyter_output><empty_output><jupyter_text>input size= 4, filter size= 3, padding= 0, Stride= 2, output_padding = 0<jupyter_code>nn.ZeroPad2d((1, 1, 1, 1))(x)
transpose.output_padding = 0
transpose.padding = 2
transpose.stride = 2
transpose(x)
transpose(x).shape<jupyter_output><empty_output><jupyter_text>Transpose Prac<jupyter_code>tx = torch.ones((1,2,1,1))
tx
tx.shape
deconv1 = F.interpolate(F.leaky_relu(tx), scale_factor=2)
deconv1.shape
deconv1 = nn.ConvTranspose2d(2, 4, 7, bias=False, padding=0)(deconv1)
deconv1.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14366729678638943, 'fraction_numerical': 0.04253308128544423, 'mean_word_length': 7.3994708994708995, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 42, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '7902', 'license': 'MIT', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1343, 'n_words': 245, 'path': 'Pytorch/pytorch_basic/Conv_prac.ipynb', 'repo_name': 'IzPerfect/My-dictionary', 'size': '3174'}