您好,我不明白为什么会出现标题中显示的错误,并将以下内容作为我的前向传播函数
# 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))
这作为我的 action_selection 函数:
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]
你在哪里使用你的前向功能?意思是在哪一行抛出错误?我找不到。
但总的来说:如果您不在类中使用 forward 函数,而是将其用作对象,则它实际上需要一个参数。( self 是“自动”给出的,因此您可以在类内部引用其他内容。为了更好的解释,请阅读:https : //docs.python.org/3/tutorial/classes.html)。例如,如果您尝试执行以下操作:
myObject = myClass()
myObject.forward(a,b)
它会抛出这个错误
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句