import torch
import torch.nn as nn
from torch.autograd import Variable
m = Variable(torch.randn(3, 10, 20))
nn.Conv2d(in_channels=3, out_channels=8, kernel_size=3)(m)
Traceback (most recent call last):
File "too.py", line 6, in <module>
nn.Conv2d(in_channels=3, out_channels=8, kernel_size=3)(m)
File "/home/soumith/code/pytorch/torch/nn/modules/module.py", line 206, in __call__
result = self.forward(*input, **kwargs)
File "/home/soumith/code/pytorch/torch/nn/modules/conv.py", line 237, in forward
self.padding, self.dilation, self.groups)
File "/home/soumith/code/pytorch/torch/nn/functional.py", line 43, in conv2d
return f(input, weight, bias)
RuntimeError: expected 3D tensor
๋ชจ์(batch_size, height, weight)์ด ์๋ ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ฌํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ณ ์์น 1์ 1์ฐจ์์ด ์ถ๊ฐ๋๊ณ ๋ฌธ์ ๊ฐ ์ ๋ ฌ๋์์ต๋๋ค. ์ถ์ . ๋๋ in_channels = 1์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
torch/csrc/autograd/functions/convolution.cpp
์ view4d
ํธ์ถ์ด ๊ฐ์ค์น ํ
์๋ 3D์ผ ๊ฒ์ผ๋ก ์์ํ๊ธฐ ๋๋ฌธ์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
๊ทธ๋ฌ๋ (3D) ์ ๋ ฅ์ (3, 10, 1, 20) ๋ชจ์์ 4D ํ ์๋ก ๋ณํ๋ฉ๋๋ค. ๊ฐ์ค์น ํ ์๋ฅผ ํ๋ ค๊ณ ํ์ง ์๋๋ผ๋ ํฌ๊ธฐ๊ฐ ์ผ์นํ์ง ์์ต๋๋ค.
์๋ง๋ ์ฐ๋ฆฌ๋ if input.dim() != 4
๋ฅผ ์ฌ๋ฆฌ๊ธฐ ์ํด Python ์์ค( nn.functional.conv2d
)์์ ๊ฒ์ฌ๋ฅผ ์ถ๊ฐํด์ผ ํฉ๋๊น?
@soumith ๋ง์กฑํ์๋ฉด PR ๋ณด๋ด๋๋ฆด๊ฒ์
๋ค! ์ด๊ฒ์ ๋งค์ฐ ๋ง์กฑํฉ๋๋ค. PR์ ๋ณด๋ด์ฃผ์ธ์ :)
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ค! ์ด๊ฒ์ ๋งค์ฐ ๋ง์กฑํฉ๋๋ค. PR์ ๋ณด๋ด์ฃผ์ธ์ :)