Issue
Hello I do not understand why i get the error as shown in title with the following as my forward propagation function
# For function that will activate neurons and perform forward propagation
def forward(self, inputs):
state, (hx, cx) = inputs # getting separately the input images to the tuple (hidden states, cell states)
x = F.relu(self.lstm(state)) # forward propagating the signal from the input images to the 1st convolutional layer
hx, cx = self.lstm(x, (hx, cx)) # the LSTM takes as input x and the old hidden & cell states and ouputs the new hidden & cell states
x = hx # getting the useful output, which are the hidden states (principle of the LSTM)
return self.fcL(x), (hx, cx) # returning the output of the actor (Q(S,A)), and the new hidden & cell states ((hx, cx))
and this as my action_selection function:
def select_action(self, state):
#LSTM
initialise = True # Initialise to zero at first iteration
if initialise:
cx = Variable(torch.zeros(1, 30))
hx = Variable(torch.zeros(1, 30))
else: # The hx,cx from the previous iteration
cx = Variable(cx.data)
hx = Variable(hx.data)
initialise = False
q_values, (hx,cx) = self.model(Variable(state), (hx,cx))
probs = F.softmax((q_values)*self.tau,dim=1)
#create a random draw from the probability distribution created from softmax
action = probs.multinomial()
return action.data[0,0]
Solution
Where do you use your forward-function? Meaning in which line does it throw the error? I can't find it.
But in general: If you use the function forward not inside your class, but as an object it actually takes one argument. (self is given "automatically", so you can reference inside the class to other stuff. For better explanation just read this: https://docs.python.org/3/tutorial/classes.html ). So for example if you try to do something like this:
myObject = myClass()
myObject.forward(a,b)
it will throw exactly this error
Answered By - Rend
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.