반응형
Grouped convolution - PyTorch Code
Standard vs. grouped convolutions: (a) In a standard convolution S, each filter is convolved with all of the input's channels; (b) In a grouped convolution with two groups G(2), half of the filters are applied to each half of the input for a 2× reduction in parameters used. More generally, a grouped convolution with g groups uses g× fewer parameters.
- Input Channel(C_in) 을 g개의 group으로 분리한다.
- 각 group 을 독립적으로 Convolution 연산을 수행한다.
- 장점 : 병렬 처리에 유리, 구현 간단, 기존 2D convolution에 비해 낮은 parameter 수
- nn.Conv2d() 함수에서 groups(default : 1)의 값을 바꿔주면 된다.
- parameter : (C_in * Kernel_szie^2 * C_out) / g
- 단점 : 직접 group 개수를 설정해야 함. 많은 그룹으로 분할시 오히려 성능하락.
import torch.nn as nn
class ConvBNReLU(nn.Module):
def __init__(self, C_in, C_out, kernel_size, stride, padding, g, affine=True):
super(ConvBNReLU, self).__init__()
self.op = nn.Sequential(
nn.Conv2d(C_in, C_out, kernel_size, stride=stride, padding=padding, bias=False, groups=g),
nn.BatchNorm2d(C_out, affine=affine),
nn.ReLU(inplace=False)
)
def forward(self, x):
return self.op(x)
2021.08.12 - [AI/ML & DL] - [ CNN ] 3. Pointwise Convolution - PyTorch Code
[ 참고자료 ]
https://eehoeskrap.tistory.com/431
https://hichoe95.tistory.com/48
https://www.slideshare.net/ssuser6135a1/ss-106656779
반응형
'Artificial Intelligence > Neural Networks' 카테고리의 다른 글
[ CNN ] 4. Depth-wise convolution - PyTorch Code (0) | 2021.08.12 |
---|---|
[ CNN ] 3. Point-wise convolution - PyTorch Code (0) | 2021.08.12 |
[ CNN ] 1. 바닐라 합성곱(vanilla convolution) - PyTorch Code (0) | 2021.08.11 |
[ GAN ] GAN(Generative Adversarial Network)의 간단한 이해 (0) | 2021.08.10 |
[CNN] Padding 무엇인가? (0) | 2020.03.16 |