티스토리 뷰

 

5x5 크기의 이미지가 3x3 커널과 stride 크기가 2인 Convolution과정에 의해 2x2사이즈의 이미지로 축소되었다고 가정해 보자. 축소된 2x2 크기의 이미지를 다시 5x5 크기의 이미지 혹은 다른 크기의 이미지로 확대시키는 과정을 Upsampling이라고 한다.

 

Transposed Convolution은 Convolution과정을 통해 Upsampling할 수 있는 한가지 방법이다. 흔히, Deconvolution이라고도 불리기도 하지만 Transposed Convolution과 Deconvolution은 다른 연산 과정을 통해 Upsampling을 진행한다.

 

Deconvolution은 Convolution과정에서 사용되었던 수학적 연산의 역 계산을 통하여 이미지를 Upsampling한다.

Convolution과 Deconvolution

 

 

Transposed Convolution은 Upsampling대상인 이미지에 padding을 더하여 convolution을 과정을 진행함으로써 이미지의 크기를 확대시킨다.

Transposed Convolution

 

Convolution과정 없이 단순하게 데이터의 차원을 늘릴 수도 있는데, 파이토치 함수에서 nn.Upsample, nn.UpsamplingNearest2d나 uu.UpsamplingBilinear2d등의 함수를 이용할 수 있다. 그중 nearest방식으로 upsampling한 예시는 아래와 같다.

>>> input_tensor = torch.arange(1, 5, dtype=torch.float32).view(1, 1, 2, 2)
>>> print(input_tensor)
tensor([[[[1., 2.],
          [3., 4.]]]])

>>> upsampled_nearest = nn.Upsample(scale_factor=2, mode='nearest')
# or nn.UpsamplingNearest2d(scale_factor=2)
>>> upsampled_nearest(input_tensor)
tensor([[[[1., 1., 2., 2.],
          [1., 1., 2., 2.],
          [3., 3., 4., 4.],
          [3., 3., 4., 4.]]]])
          
>>> upsampled_nearest = nn.Upsample(scale_factor=(2,3), mode='nearest') 
# or nn.UpsamplingNearest2d(scale_factor=(2,3)))
>>> upsampled_nearest(input_tensor)
tensor([[[[1., 1., 1., 2., 2., 2.],
          [1., 1., 1., 2., 2., 2.],
          [3., 3., 3., 4., 4., 4.],
          [3., 3., 3., 4., 4., 4.]]]])

 

 

 

참고

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함