import torch.nn.functional as F
bs = 10
F.one_hot(torch.ones(bs)*2, 5)
2์ ๋์๋๋ ์ ์ฒด ํฌ๊ธฐ๋ 5์ธ one hot encoding vector๋ฅผ batch size๊ฐ์๋งํผ ๋ง๋ค๊ณ ์ถ์ด์ ์์ ๊ฐ์ด ์ฝ๋๋ฅผ ์์ฑํ๋ฉด ๋ฐํ์ ์๋ฌ๊ฐ ๋ฌ๋ค.
RuntimeError: one_hot is only applicable to index tensor.
one_hot ํจ์๋ index tensor (ํ์ ๋ช ์ด torch.int64)๋ฅผ ์ ๋ ฅ์ผ๋ก ๋ฐ๊ธฐ ๋๋ฌธ์ ๋ฐ์ํ๋ ์๋ฌ์ด๋ค. ๋ค์๊ณผ ๊ฐ์ด ์์ ํด์ฃผ๋ฉด ๋๋ค.
>>> torch.nn.functional.one_hot((torch.ones(bs)*2).to(torch.int64), 5)
tensor([[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 1, 0, 0]])
๋ โผ๏ธ
๋ฐ์ํ
'IN DEPTH CAKE > Coding-WIKI' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
sphinx-js ๋ก javascript ์ฝ๋ ๋ฌธ์ํํ๊ธฐ (0) | 2023.05.03 |
---|---|
No module named 'tensorboard' ํด๊ฒฐ (0) | 2023.03.28 |
[python] Anaconda ํ๊ฒฝ yamlํ์ผ export ๋ฐ import (ํ๊ฒฝ ์์ฑ create, ํ์ฑํ activate ๋ฑ) (0) | 2023.03.17 |
[C++] reference ๋ณ์์ ๋ํ ์ดํด (pointer์ ๋น๊ต) (1) | 2023.03.14 |
<VSCode ๋ฅผ C++ IDE๋ก ์ฐ๊ธฐ> Mac์์ C++ ๊ฐ๋ฐํ๊ธฐ (6) | 2023.03.07 |