Recent Posts
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 딥러닝
- 머신러닝
- pytorch
- 자료구조
- 3d
- Front
- clean code
- math
- Python
- REACT
- Meta Learning
- nerf
- Vision
- web
- GAN
- ML
- dl
- computervision
- PRML
- Torch
- classification
- algorithm
- Depth estimation
- FineGrained
- 알고리즘
- SSL
- nlp
- FGVC
- cs
- CV
- Today
- Total
KalelPark's LAB
[PYTORCH] nn.Unfold란? 본문

Pytorch unfold란?
Batched tensor에 대하여, 마치 Convolution처럼, Slidingg하면서, locl block을 구하는 것이다.
예를들면, 해당 MNIST의 경우 1, 1, 28, 28 사이즈의 경우 -> 1, 49, 16 으로 변환한 것이다.


EX)
import torch.nn as nn
from matplotlib import pyplot as plt
from torchvision import datasets, transforms
if __name__ == '__main__':
train_data = datasets.MNIST(root='./data/',
train=True,
download=True,
transform=transforms.ToTensor())
test_data = datasets.MNIST(root='./data/',
train=False,
download=True,
transform=transforms.ToTensor())
image, label = train_data[0]
image = image.unsqueeze(0) # 1, 1, 28, 28
print(image.size())
unfold = nn.Unfold(kernel_size=2, stride=2, padding=0)
x = unfold(image)
fig, axs = plt.subplot_mosaic([['left', 'right']], layout='constrained')
axs['left'].imshow(image.squeeze().numpy(), cmap='gray')
x = x[:, 0, ...].view(1, 1, 14, 14)
axs['right'].imshow(x.squeeze().numpy(), cmap='gray')
plt.show()

주요 사용 용도 :
1) https://runebook.dev/ko/docs/pytorch/generated/torch.nn.unfold
2) https://www.facebook.com/groups/PyTorchKR/posts/1685133764959631/
Reference
https://pytorch.org/docs/stable/generated/torch.nn.Unfold.html
Unfold — PyTorch 2.0 documentation
Shortcuts
pytorch.org
'Python > Pytorch' 카테고리의 다른 글
[Pytorch] processing time 정확히 측정하기 - torch.cuda.synchronize() (0) | 2023.03.22 |
---|---|
[Pytorch] Multi-GPU 제대로 사용하기 (0) | 2023.03.19 |
[Pytorch] torch.gather 코드로 간략하게 이해하기 (0) | 2023.03.16 |
[ Pytorch ] Tensor를 나누는 방법들, Split, Chunk란? (0) | 2023.01.25 |
[ Pytorch ] Data Sampler & Sequence Bucketing? (0) | 2023.01.24 |