def forward(self, top_buf, top_stack_1, top_stack_2): if self.tracking_ln: top_buf = self.buf_ln(top_buf) top_stack_1 = self.stack1_ln(top_stack_1) top_stack_2 = self.stack2_ln(top_stack_2) if self.lateral_tracking: tracker_inp = self.buf(top_buf) tracker_inp += self.stack1(top_stack_1) tracker_inp += self.stack2(top_stack_2) batch_size = tracker_inp.size(0) if self.h is not None: tracker_inp += self.lateral(self.h) if self.c is None: self.c = to_gpu( Variable(torch.from_numpy( np.zeros((batch_size, self.state_size), dtype=np.float32)), volatile=tracker_inp.volatile)) # Run tracking lstm. self.c, self.h = lstm(self.c, tracker_inp) return self.h, self.c else: return torch.cat([top_buf, top_stack_1, top_stack_2], 1), None
def forward(self, top_buf, top_stack_1, top_stack_2): tracker_inp = self.buf(top_buf.h) tracker_inp += self.stack1(top_stack_1.h) tracker_inp += self.stack2(top_stack_2.h) batch_size = tracker_inp.size(0) if self.lateral_tracking: if self.h is not None: tracker_inp += self.lateral(self.h) if self.c is None: self.c = to_gpu(Variable(torch.from_numpy( np.zeros((batch_size, self.state_size), dtype=np.float32)), volatile=tracker_inp.volatile)) # Run tracking lstm. self.c, self.h = lstm(self.c, tracker_inp) return self.h, self.c else: outp = self.transform(tracker_inp) return outp, None