To get this to work I had to implement a forward as well:
class ActorCritic(nn.Module):
def __init__(self, state_dim, action_dim, n_latent_var):
super(ActorCritic, self).__init__()
#... same as your code
def forward(self, state_input):
return torch.tensor(self.act(state_input, None))
def act(self, state, memory):
if type(state) is np.ndarray:
state = torch.from_numpy(state).float().to(device)
action_probs = self.action_layer(state)
# here make a filter for only possible actions!
#probs = probs * memory.leagalCards
dist = Categorical(action_probs)
action = dist.sample()
if memory is not None:
memory.states.append(state)
memory.actions.append(action)
memory.logprobs.append(dist.log_prob(action))
return action.item()
Hey,
Thanks for sharing this awesome code!
I would like to export my result also as onnx model. However I have no idea how to use it then... currently it did not work for me:
This is how I export it:
To get this to work I had to implement a forward as well:
Now I tried to use my onnx model like this:
But it returns always the same action :(
Any ideas what is going wrong here?