Пример #1
0
 def decode(self, enc):
     enc = enc.repeat(self.out_length, 1, 1)
     h_dec, _ = self.dec_lstm(enc)
     h_dec = h_dec.permute(1, 0, 2)
     fut_pred = self.op(h_dec)
     fut_pred = fut_pred.permute(1, 0, 2)
     fut_pred = outputActivation(fut_pred)
     return fut_pred
	def decode(self, enc):
		if self.use_attention: # Attention builds on top of seq2seq
			m = enc.size(0)
			if self.use_cuda:
				h0 = torch.zeros(self.num_layers, m, self.decoder_size).cuda() # [SeqLen, Batch, decoder size]
			else:
				h0 = torch.zeros(self.num_layers, m, self.decoder_size) # [1, 128, 128]
			c0 = y0 = h0

			enc = torch.cat((enc, self.hist_enc_back, self.grid_enc_back), 1)
			enc = self.proj_seq2seq(enc) # proj from [Batch, 117] to [Batch, 128]
			yn = enc.unsqueeze(0) # [1, Batch 128, decoder size 128]
			context = self.one_step_attention(self.hist_a, h0).unsqueeze(0)
			yn, (hn, cn) = self.dec_seq2seq(context, (h0, c0))
			h_dec = yn
			for t in range(self.out_length - 1):
				context = self.one_step_attention(self.hist_a, hn).unsqueeze(0)
				yn, (hn, cn) = self.dec_seq2seq(context, (hn, cn))
				h_dec = torch.cat((h_dec, yn), dim=0)
		elif self.use_seq2seq:
			m = enc.size(0)
			if self.use_cuda:
				self.h0 = torch.zeros(self.num_layers, m, self.decoder_size).cuda() # [SeqLen, Batch, decoder size]
			else:
				self.h0 = torch.zeros(self.num_layers, m, self.decoder_size) # [1, 128, 128]
			self.c0 = self.y0 = self.h0

			#pdb.set_trace()
			enc = torch.cat((enc, self.hist_enc_back, self.grid_enc_back), 1)
			enc = self.proj_seq2seq(enc) # proj from [Batch, 117] to [Batch, 128]
			encout = enc.unsqueeze(0) # [1, Batch 128, decoder size 128]
			#yn, (hn, cn) = self.dec_seq2seq(yn, (self.h0, self.c0))
			yn, (hn, cn) = self.dec_seq2seq(encout, (self.h0, self.c0))
			#yn, (hn, cn) = self.dec_seq2seq(self.y0, (encout, encout))
			h_dec = yn
			for t in range(self.out_length - 1):
				yn, (hn, cn) = self.dec_seq2seq(yn, (hn, cn))
				h_dec = torch.cat((h_dec, yn), dim=0)
		else:
			# enc: [batch 128, feats 117]
			# we just repeat hn output, not using a_1 up to a_Tx (TODO via ATTENTION)
			# enc: [5sec 25, batch 128, feats 117] after repeat
			enc = enc.repeat(self.out_length, 1, 1)
			# And now we retrieve the T_y=25 outputs and discard (hn, cn)
			# h_dec: [25, 128, 128] via nn.LSTM(feats 117, hid 128)
			h_dec, _ = self.dec_lstm(enc)

		# h_dec: [batch 128, Ty 25, hid 128] via permute(1, 0, 2)
		h_dec = h_dec.permute(1, 0, 2)
		# fut_pred: [batch 128, Ty 25, bivariate gaussian params 5] via self.op=nn.Linear(128, 5)
		fut_pred = self.op(h_dec)
		# fut_pred: [Ty 25, batch 128, 5] via permute
		fut_pred = fut_pred.permute(1, 0, 2)
		fut_pred = outputActivation(fut_pred)
		# fut_pred: [Ty 25, batch 128, bivariate gaussian params 5] via outputActivation which enforces pred constraints
		return fut_pred
Пример #3
0
 def decode(self,enc):
     #print (enc.size()) # (128, 117)
     enc = enc.repeat(self.out_length, 1, 1)
     #print (enc.size()) # (25, 128, 117), why 25? because we want to predict future 50 timesteps histories and the downsampling rate is 2
     h_dec, _ = self.dec_lstm(enc) # (25, 128, 128)
     h_dec = h_dec.permute(1, 0, 2) # (128, 25, 128)
     fut_pred = self.op(h_dec) # (128, 25, 5)
     fut_pred = fut_pred.permute(1, 0, 2) # (25, 128, 5) 25 timesteps, 128 batchsize, 5 prediction
     fut_pred = outputActivation(fut_pred)
     return fut_pred
Пример #4
0
    def decode_by_step(self, enc):

        pre_traj = []

        decoder_input = enc

        for _ in range(self.out_length):
            decoder_input = decoder_input.unsqueeze(0)
            h_dec, _ = self.dec_lstm(decoder_input)
            h_for_pred = h_dec.squeeze()
            fut_pred = self.op(h_for_pred)
            pre_traj.append(fut_pred.view(fut_pred.size()[0], -1))

            embedding_input = fut_pred
            decoder_input = self.spatial_embedding(embedding_input)

        pre_traj = torch.stack(pre_traj, dim=0)
        pre_traj = outputActivation(pre_traj)
        return pre_traj