I have a PPO agent and give it a tensor of size (1, 128, 100) as input (state).
The state of the environment is a numpy array (128, 100) and then convert to tensor.
The neural network:
state_dim = env.observation_space.shape[0] #128
hidden_dim = 64
action_dim = 20 (discrete)
class Actor(nn.Module):
def __init__(self, state_dim, hidden_dim, action_dim):
super(Actor, self).__init__()
self.action_layer = nn.Sequential(
nn.Linear(state_dim, hidden_dim),
nn.Relu(),
nn.Linear(hidden_dim, hidden_dim),
nn.Relu(),
nn.Linear(hidden_dim, action_dim),
nn.Softmax(dim=-1)).float().to(device)
def forward(self, state):
action_probs = self.action_layer(state)
return action_probs
I got this error:
File "main.py", line 167, in <module> PPO.main(args) action_probs = self.actor(state) File "Anaconda\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "PPO.py", line 125, in forward action_probs = self.action_layer(state) File "Anaconda\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "Anaconda\lib\site-packages\torch\nn\modules\container.py", line 119, in forward input = module(input) File "Anaconda\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "Anaconda\lib\site-packages\torch\nn\modules\linear.py", line 94, in forward return F.linear(input, self.weight, self.bias) File "Anaconda\lib\site-packages\torch\nn\functional.py", line 1753, in linear return torch._C._nn.linear(input, weight, bias) RuntimeError: mat1 dim 1 must match mat2 dim 0
Any advice?
Thanks.