Notice
Recent Posts
Recent Comments
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
- MDP
- DART
- Computer Architecture
- Image Processing
- PCA
- 파이토치 트랜스포머를 활용한 자연어 처리와 컴퓨터비전 심층학습
- BFS
- ARM
- ML
- 영상처리
- C++
- Kaggle
- fastapi를 사용한 파이썬 웹 개발
- Got
- BOF
- Flutter
- pytorch
- system hacking
- 백준
- rao
- bloc
- llm을 활용 단어장 앱 개발일지
- BAEKJOON
- FastAPI
- study book
- MATLAB
- Algorithm
- Stream
- Dreamhack
- Widget
Archives
- Today
- Total
Bull
[pytorch] einops.rearrange() 본문
pip install einops
from einops import rearrange
x = torch.randn(64, 3, 32, 32)
patch_size = 4 # 4 pixels
print('x :', x.shape)
patches = rearrange(x, 'b c (h s1) (w s2) -> b (h w) (s1 s2 c)', s1=patch_size, s2=patch_size)
# 64 3 32 32 = 64 3 8*4 8*4 -> 64 8*8 4*4*3
print('patches :', patches.shape)
x : torch.Size([64, 3, 32, 32])
patches : torch.Size([64, 64, 48])
rearrange(x, 'b c (h s1) (w s2) -> b (h w) (s1 s2 c)', s1=patch_size, s2=patch_size)
64 3 32 32에서 32를 (8 * 4)로 끊어서 텐서를 나눠 줄 수 있다.
즉 3번째 자리에 보이는 (h s1)을 h와 s1으로 나눌 수 있다.
그러니까 [64, 3, 32, 32] → [64, 3, (8 4), (8 4)] → [64, (8 8), (4 4 3)] → [64, 64, 48] 텐서로 변환해준다.
'AI programming > pytorch' 카테고리의 다른 글
[pytorch] Tensor 정리 | study book (0) | 2024.08.09 |
---|