일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- PRML
- REACT
- Torch
- GAN
- cs
- nlp
- dl
- clean code
- CV
- web
- Meta Learning
- Front
- 3d
- 알고리즘
- Vision
- algorithm
- SSL
- 자료구조
- 머신러닝
- 딥러닝
- classification
- Depth estimation
- nerf
- ML
- computervision
- FineGrained
- Python
- FGVC
- pytorch
- math
- Today
- Total
KalelPark's LAB
[ Pytorch ] Chunk 활용하기 본문
Chunk
- Tensor를 지정된 Chunk의 개수로 분할하려고 합니다. 각 Chunk는 입력 텐서의 View이다.
- torch.tensor_split()은 항상 명확하게, Chunk하지만, torch.Chunk는 작거나, 같게 합니다. (유연성)
import torch
chunk_example = torch.arange(12)
print(chunk_example)
-> tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
print(chunk_example.size())
-> torch.Size([12])
print(chunk_example.chunk(6, dim = -1))
-> (tensor([0, 1]), tensor([2, 3]), tensor([4, 5]), tensor([6, 7]), tensor([8, 9]), tensor([10, 11]))
* 하단 링크의 예시
import torch
batch_size, nmic, nsample = 3, 6, 64000
x = torch.randn(batch_size, nmic, nsample) # [3, 6, 64000]
mic1, mic2, mic3, mic4, mic5, mic6 = torch.chunk(x, nmic, dim = 1)
print(mic1.size(), mic2.size(), mic3.size(), mic4.size(), mic5.size(), mic6.size())
-> torch.Size([3, 1, 64000]) torch.Size([3, 1, 64000]) torch.Size([3, 1, 64000]) torch.Size([3, 1, 64000]) torch.Size([3, 1, 64000]) torch.Size([3, 1, 64000])
참조
[PyTorch] Tensor 자르기/분리하기: chunk함수
Chunk함수란? chunk함수는 tensor를 쪼개는 함수이다. tensor를 몇개로 어떤 dimension으로 쪼갤지 설정해주고 사용하면된다. output = torch.chunk(input, n = (몇개로 쪼갤지 설정), dim = (어떤 차원에 적용할지)) i
sanghyu.tistory.com
https://pytorch.org/docs/stable/generated/torch.chunk.html#torch-chunk
torch.chunk — PyTorch 1.13 documentation
Shortcuts
pytorch.org
https://github.com/pytorch/pytorch/blob/master/torch/csrc/api/include/torch/data/datasets/chunk.h
GitHub - pytorch/pytorch: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Tensors and Dynamic neural networks in Python with strong GPU acceleration - GitHub - pytorch/pytorch: Tensors and Dynamic neural networks in Python with strong GPU acceleration
github.com
'Python > Pytorch' 카테고리의 다른 글
[ Pytorch ] Tensor를 나누는 방법들, Split, Chunk란? (0) | 2023.01.25 |
---|---|
[ Pytorch ] Data Sampler & Sequence Bucketing? (0) | 2023.01.24 |
[ Pytorch ] meshgrid, cumsum란? (0) | 2023.01.23 |
[ Pytorch ] Logsumexp 활용하기 (0) | 2023.01.05 |
[ Pytorch ] register_buffer, register_parameter란? (0) | 2022.12.29 |