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 | 31 |
Tags
- pytorch
- nlp
- Python
- PRML
- 알고리즘
- clean code
- REACT
- 3d
- Torch
- Vision
- FGVC
- math
- 머신러닝
- ML
- 자료구조
- computervision
- Meta Learning
- classification
- cs
- CV
- dl
- SSL
- nerf
- Front
- FineGrained
- Depth estimation
- algorithm
- GAN
- web
- 딥러닝
- 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])
참조
https://pytorch.org/docs/stable/generated/torch.chunk.html#torch-chunk
https://github.com/pytorch/pytorch/blob/master/torch/csrc/api/include/torch/data/datasets/chunk.h
'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 |
Comments