【发布时间】:2018-03-07 09:39:09
【问题描述】:
你好,我不明白为什么我会得到标题所示的错误,下面是我的前向传播函数
# 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函数。 -
修正缩进。