본문으로 바로가기

[PyTorch] Convolution

category AI/PyTorch 2019. 10. 29. 11:37
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

 

 

 

 

[Conv2d]

torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros')

 

out_channels에 따라 결과 feature map의 channel 수가 결정됨.

 

The parameters kernel_size, stride, padding, dilation can either be:

  • a single int – in which case the same value is used for the height and width dimension

  • a tuple of two ints – in which case, the first int is used for the height dimension, and the second int for the width dimension

 

 

 

위의 cross-correlation 연산에 관하여...

convolution 연산을 한다고 해놓고 왜 실제로는 cross-correlation 연산을 하느냐?

둘의 차이는 필터를 뒤집는 차이이다.

 

 

convolution의 경우 필터를 반대로 뒤집어서 사용하고 cross-correlation의 경우는 필터 그대로를 사용한다.

하지만 어차피 우리의 목표는 필터의 값을 학습하려는 것이기 때문에 뒤집으나 마나 동일.

 

 

 

 

[MaxPool2d]

torch.nn.MaxPool2d(kernel_size, stride=None, padding=0, dilation=1, return_indices=False, ceil_mode=False)

 

가장 큰 값 뽑아줌.

 

[사용법]

import torch

inp = torch.Tensor(1, 1, 28, 28)

conv = torch.nn.Conv2d(1, 5, 5)
pool = torch.nn.MaxPool2d(2)

out = conv(inp)
out = pool(out)

 

 

 

 

 

'AI > PyTorch' 카테고리의 다른 글

간단 순서 정리  (0) 2019.11.13
[PyTorch] MNIST CNN  (0) 2019.11.06
[PyTorch] MNIST with Batch Normalization  (0) 2019.10.29
[PyTorch] MNIST with Dropout  (0) 2019.10.28
[PyTorch] MNIST with ReLU and Weight Initialization  (0) 2019.10.28