前提・実現したいこと
Python初心者です。
AlexNetで3次元データをクラス分類したいのですが、MaxPool3dの使い方がわからず
RuntimeErrorになってしまいます。nn.Conv3d部分も正しいかわかりません。
間違っている箇所あればご指摘いただけますと幸いです。
発生している問題・エラーメッセージ
$ python AlexNet.py Traceback (most recent call last): File "AlexNet.py", line 134, in <module> outputs = net(images) File "/home/selen/.pyenv/versions/3.7.3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__ result = self.forward(*input, **kwargs) File "AlexNet.py", line 107, in forward x = self.features(x) File "/home/selen/.pyenv/versions/3.7.3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__ result = self.forward(*input, **kwargs) File "/home/selen/.pyenv/versions/3.7.3/lib/python3.7/site-packages/torch/nn/modules/container.py", line 92, in forward input = module(input) File "/home/selen/.pyenv/versions/3.7.3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__ result = self.forward(*input, **kwargs) File "/home/selen/.pyenv/versions/3.7.3/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 476, in forward self.padding, self.dilation, self.groups) RuntimeError: Expected 5-dimensional input for 5-dimensional weight 64 3 3 3, but got 4-dimensional input of size [64, 80, 96, 80] instead
該当のソースコード
Python
1class AlexNet(nn.Module): 2 3 def __init__(self, num_classes): 4 super(AlexNet, self).__init__() 5 self.features = nn.Sequential( 6 nn.Conv3d(3, 64, kernel_size=3, padding=1), 7 nn.ReLU(inplace=True), 8 nn.MaxPool3d((80, 96, 80), stride=(2, 2, 2)), 9 10 nn.Conv3d(64, 192, kernel_size=5, padding=2), 11 nn.ReLU(inplace=True), 12 nn.MaxPool3d((80, 96, 80), stride=(2, 2, 2)), 13 14 nn.Conv3d(192, 384, kernel_size=3, padding=1), 15 nn.ReLU(inplace=True), 16 17 nn.Conv3d(384, 256, kernel_size=3, padding=1), 18 nn.ReLU(inplace=True), 19 20 nn.Conv3d(256, 256, kernel_size=3, padding=1), 21 nn.ReLU(inplace=True), 22 nn.MaxPool3d((80, 96, 80), stride=(2, 2, 2)), 23 ) 24 25 self.classifier = nn.Sequential( 26 nn.Dropout(), 27 nn.Linear(256 * 4 * 4, 4096), 28 nn.ReLU(inplace=True), 29 30 nn.Dropout(), 31 nn.Linear(4096, 4096), 32 nn.ReLU(inplace=True), 33 34 nn.Linear(4096, num_classes), 35 ) 36 37 def forward(self, x): 38 x = self.features(x) 39 x = x.view(x.size(0), 256 * 4 * 4) 40 x = self.classifier(x) 41 return x 42
あなたの回答
tips
プレビュー