Hi :),
I’, using Alexnet to recognice euler angles of Persons in front of a Camera. This is my model:
class AlexNet(nn.Module):
def __init__(self, num_classes=1000):
super(AlexNet, self).__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=11, stride=4, padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(64, 192, kernel_size=5, padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(192, 384, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(384, 256, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(256, 256, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
)
self.classifier = nn.Sequential(
nn.Dropout(),
nn.Linear(256 * 6 * 6, 4096),
nn.ReLU(inplace=True),
nn.Dropout(),
nn.Linear(4096, 4096),
nn.ReLU(inplace=True),
nn.Linear(4096, num_classes),
)
def forward(self, x):
x = self.features(x)
x = x.view(x.size(0), 256 * 6 * 6)
x = self.classifier(x)
#print(self.classifier.parameters())
return x
def alexnet(pretrained=True, **kwargs):
model = AlexNet(**kwargs)
if pretrained:
model.load_state_dict(model_zoo.load_url(model_urls[‘alexnet’]))
model.classifier._modules[‘6’] = nn.Linear(4096, 3)
return model
i modified the last Layer to only 3 outputs (the angles). My Goal now is to replace the 3 Linear Layers (The 2 in die classifier and my changed one) with RNN Layers. Preferable still trained (of course only the ih weight. The hh weigts needs to be trained. And of cource only from the first 2 Layers. My changed 3 Layer needs to be trained completly) To test this i tried to change my changed Leniar Layer(4069, 3) to a RNN Layer(4069, 3) Just like this:
model.classifier._modules[‘6’] = nn.RNN(4096, 3)
But when I’m trying to do so, I get this error:
…
File “/home/jan/anaconda3/envs/TensorboardX/lib/python3.6/site-packages/torch/nn/modules/rnn.py”, line 178, in forward
self.check_forward_args(input, hx, batch_sizes)
File “/home/jan/anaconda3/envs/TensorboardX/lib/python3.6/site-packages/torch/nn/modules/rnn.py”, line 126, in check_forward_args
expected_input_dim, input.dim()))
RuntimeError: input must have 3 dimensions, got 2
My Input is a [32, 3, 244, 244] Tensor.
What do I do wrong?