import copy #导入拷贝库import numpy as np #导入数值计算库,以后调用采用np缩写
import torch #导入torch库包含一些常用的数据类型
import torch.nn as nn #导入torch中的网络层以后调用采用nn缩写,例如nn.liner()
import torch.nn.functional as F #导入torch中的一些函数,例如常用的激活函数from .multi_attention_forward import multi_head_attention_forward
#.表示在当前目录下multi_attention_forward.py,导入multi_head_attention_forward函数def get_noise(shape, noise_type):#定义一个函数get_noise,输入参数为shape,noise_type,shape-表示数据结构,比如2行2列(2,2) noise_type字符串型if noise_type == "gaussian":#如果noise_type为高斯return torch.randn(shape).cuda()#生成标准正态分布,数据结构为shape-(x,y),放入cuda中,返回elif noise_type == "uniform":#如果为均匀分布return torch.rand(*shape).sub_(0.5).mul_(2.0).cuda()#生成均匀分布(0,1),然后-0.5得到(-0.5,0.5),再乘以2得到(-1,1)的均匀分布,数据结构为shape-(x,y),放入到cuda中,返回raise ValueError('Unrecognized noise type "%s"' % noise_type)#如果nosie_type不是前两种情况,报错def get_subsequent_mask(seq):#定义一个函数get_subsequent_mask,输入参数为seq,其中seq第一维度表示数据集场景,第二维表示障碍物编号''' For masking out the subsequent info. '''sz_b, len_s = seq.size()#得到seq数据结构比如(3,6)subsequent_mask = (1 - torch.triu(torch.ones((1, len_s, len_s), device=seq.device), diagonal=1)).bool() #得到下三角矩阵,并放入到seq.device中,数据变为bool型即{True,False}.过程见下↓return subsequent_mask#返回
(1−torch.triu(torch.ones((1,lens,lens),device=seq.device),diagonal=1)).bool()数据变化(1 - torch.triu( torch.ones((1, len_s, len_s), device=seq.device), diagonal=1)).bool() 数据变化(1−torch.triu(torch.ones((1,lens,lens),device=seq.device),diagonal=1)).bool()数据变化
[11⋯111⋯1⋮⋮⋱⋮11⋯1]\begin{bmatrix} {1}&{1}&{\cdots}&{1}\\ {1}&{1}&{\cdots}&{1}\\ {\vdots}&{\vdots}&{\ddots}&{\vdots}\\ {1}&{1}&{\cdots}&{1}\\ \end{bmatrix}⎣⎢⎢⎢⎡11⋮111⋮1⋯⋯⋱⋯11⋮1⎦⎥⎥⎥⎤[11⋯101⋯1⋮⋮⋱⋮00⋯1]\begin{bmatrix} {1}&{1}&{\cdots}&{1}\\ {0}&{1}&{\cdots}&{1}\\ {\vdots}&{\vdots}&{\ddots}&{\vdots}\\ {0}&{0}&{\cdots}&{1}\\ \end{bmatrix}⎣⎢⎢⎢⎡10⋮011⋮0⋯⋯⋱⋯11⋮1⎦⎥⎥⎥⎤[01⋯100⋯1⋮⋮⋱⋮00⋯0]\begin{bmatrix} {0}&{1}&{\cdots}&{1}\\ {0}&{0}&{\cdots}&{1}\\ {\vdots}&{\vdots}&{\ddots}&{\vdots}\\ {0}&{0}&{\cdots}&{0}\\ \end{bmatrix}⎣⎢⎢⎢⎡00⋮010⋮0⋯⋯⋱⋯11⋮0⎦⎥⎥⎥⎤[1−01−1⋯1−11−01−0⋯1−1⋮⋮⋱⋮1−01−0⋯1−0]\begin{bmatrix} {1-0}&{1-1}&{\cdots}&{1-1}\\ {1-0}&{1-0}&{\cdots}&{1-1}\\ {\vdots}&{\vdots}&{\ddots}&{\vdots}\\ {1-0}&{1-0}&{\cdots}&{1-0}\\ \end{bmatrix}⎣⎢⎢⎢⎡1−01−0⋮1−01−11−0⋮1−0⋯⋯⋱⋯1−11−1⋮1−0⎦⎥⎥⎥⎤[10⋯011⋯0⋮⋮⋱⋮11⋯1]\begin{bmatrix} {1}&{0}&{\cdots}&{0}\\ {1}&{1}&{\cdots}&{0}\\ {\vdots}&{\vdots}&{\ddots}&{\vdots}\\ {1}&{1}&{\cdots}&{1}\\ \end{bmatrix}⎣⎢⎢⎢⎡11⋮101⋮1⋯⋯⋱⋯00⋮1⎦⎥⎥⎥⎤[TrueFalse⋯FalseTrueTrue⋯False⋮⋮⋱⋮TrueTrue⋯True]\begin{bmatrix} {True}&{False}&{\cdots}&{False}\\ {True}&{True}&{\cdots}&{False}\\ {\vdots}&{\vdots}&{\ddots}&{\vdots}\\ {True}&{True}&{\cdots}&{True}\\ \end{bmatrix}⎣⎢⎢⎢⎡TrueTrue⋮TrueFalseTrue⋮True⋯⋯⋱⋯FalseFalse⋮True⎦⎥⎥⎥⎤
def _get_activation_fn(activation): #定义得到激活函数if activation == "relu":#如果采用relureturn F.relu #返回F.relu即import torch.nn.functional as F 中的torch.nn.functional.reluelif activation == "gelu":#如果采用gelureturn F.gelu#返回F.gelu即import torch.nn.functional as F 中的torch.nn.functional.geluelse:raise RuntimeError("activation should be relu/gelu, not %s." % activation)#如果不是前面的两种情况返回报错activation should be relu/gelu, not “activation”。def _get_clones(module, N):#定义得到克隆函数return nn.ModuleList([copy.deepcopy(module) for i in range(N)]) #返回n个module模型class MultiheadAttention(nn.Module):#定义一个类对象MultiheadAttention,继承nn.Moduler"""Allows the model to jointly attend to informationfrom different representation subspaces.See reference: Attention Is All You Need.. math::\text{MultiHead}(Q, K, V) = \text{Concat}(head_1,\dots,head_h)W^O\text{where} head_i = \text{Attention}(QW_i^Q, KW_i^K, VW_i^V)Args:embed_dim: total dimension of the model.num_heads: parallel attention heads.dropout: a Dropout layer on attn_output_weights. Default: 0.0.bias: add bias as module parameter. Default: True.add_bias_kv: add bias to the key and value sequences at dim=0.add_zero_attn: add a new batch of zeros to the key andvalue sequences at dim=1.kdim: total number of features in key. Default: None.vdim: total number of features in key. Default: None.Note: if kdim and vdim are None, they will be set to embed_dim such thatquery, key, and value have the same number of features.Examples::>>> multihead_attn = nn.MultiheadAttention(embed_dim, num_heads)>>> attn_output, attn_output_weights = multihead_attn(query, key, value)"""__constants__ = ['q_proj_weight', 'k_proj_weight', 'v_proj_weight', 'in_proj_weight']def __init__(self, embed_dim, num_heads, dropout=0., bias=True, add_bias_kv=False, add_zero_attn=False, kdim=None,vdim=None):super(MultiheadAttention, self).__init__() #初始化先找到 MultiheadAttention的父类nn.Module,并用nn.Module的初始化方法初始化子类MultiheadAttentionself.embed_dim = embed_dim #transfomer经过编码后的输入数据维度self.kdim = kdim if kdim is not None else embed_dim #k的维度如果输入参数有则赋值,没有计为embed_dimself.vdim = vdim if vdim is not None else embed_dim #v的维度如果输入参数有则赋值,没有计为embed_dimself._qkv_same_embed_dim = self.kdim == embed_dim and self.vdim == embed_dim #如果k与v维数相同则赋值为Trueself.num_heads = num_heads #多头个数self.dropout = dropout#定义一个dropout层为了出现过拟合,在训练时,按照伯努利分布的样本以概率P将输入张量的某些元素随机归零,输入结果放缩为 1/(1-p)
import torch.nn as nn
input = torch.ones(5,5)
m = nn.Dropout(p=0.2)
output = m(input)
print(output)
tensor([[1.2500, 1.2500, 0.0000,1.2500, 0.0000],
[1.2500, 1.2500, 1.2500, 0.0000, 1.2500],
[1.2500, 1.2500, 1.2500, 1.2500, 0.0000],
[1.2500, 1.2500, 1.2500, 1.2500, 0.0000],
[1.2500, 1.2500, 1.2500, 1.2500, 1.2500]])
1-0.2=0.8 1/0.8=1.25符合
self.head_dim = embed_dim // num_heads #整数除,计算每一个head的维数比如8//3=2assert self.head_dim * num_heads == self.embed_dim, "embed_dim must be divisible by num_heads" #判断是否整除比如上面的2 * 3 !=8 所以输出错误if self._qkv_same_embed_dim is False: #如果k v维度不一样则执行,对q k v 权重分别初始化,不注册in_proj_weightself.q_proj_weight = nn.Parameter(torch.Tensor(embed_dim, embed_dim))self.k_proj_weight = nn.Parameter(torch.Tensor(embed_dim, self.kdim))self.v_proj_weight = nn.Parameter(torch.Tensor(embed_dim, self.vdim))self.register_parameter('in_proj_weight', None)else: #如果k v维度一样则执行,对q k v 权重一起初始化,不注册q k v_proj_weightself.in_proj_weight = nn.Parameter(torch.empty(3 * embed_dim, embed_dim))self.register_parameter('q_proj_weight', None)self.register_parameter('k_proj_weight', None)self.register_parameter('v_proj_weight', None)if bias:#如果存在偏执参数,则执行self.in_proj_bias = nn.Parameter(torch.empty(3 * embed_dim))else: #否则不注册in_proj_biasself.register_parameter('in_proj_bias', None)self.out_proj = nn.Linear(embed_dim, embed_dim, bias=bias) #输出为全连接网络,网络输入数据的维度为embed_dim,输出数据的维度为embed_dim,偏执为biasif add_bias_kv:#如果 k v 存在偏执则执行self.bias_k = nn.Parameter(torch.empty(1, 1, embed_dim))self.bias_v = nn.Parameter(torch.empty(1, 1, embed_dim))else: #否则设置为noneself.bias_k = self.bias_v = Noneself.add_zero_attn = add_zero_attn #对k v按照列是否添加一些0序列self._reset_parameters()#参数进行重新设置,为什么重新设置?如果初始化值很小,那么随着层数的传递,方差就会趋于0,此时输入值 也变得越来越小,在sigmoid上就是在0附近,接近于线性,失去了非线性如果初始值很大,那么随着层数的传递,方差会迅速增加,此时输入值变得很大,而sigmoid在大输入值写倒数趋近于0,反向传播时会遇到梯度消失的问题def _reset_parameters(self):# 上面参数重新设置的调用函数采用了 nn.init.xavier_uniform_对参数重新设置[参考文献](https://blog.csdn.net/weixin_44225182/article/details/126655294)if self._qkv_same_embed_dim: #如果 k v 维度相同,统一重新设置nn.init.xavier_uniform_(self.in_proj_weight)else: #否则分别设置nn.init.xavier_uniform_(self.q_proj_weight)nn.init.xavier_uniform_(self.k_proj_weight)nn.init.xavier_uniform_(self.v_proj_weight)if self.in_proj_bias is not None:#有则初始化填充为常数0nn.init.constant_(self.in_proj_bias, 0.)nn.init.constant_(self.out_proj.bias, 0.)if self.bias_k is not None:有则重新设置nn.init.xavier_normal_(self.bias_k)if self.bias_v is not None:nn.init.xavier_normal_(self.bias_v)def __setstate__(self, state):# Support loading old MultiheadAttention checkpoints generated by v1.1.0if '_qkv_same_embed_dim' not in state:state['_qkv_same_embed_dim'] = Truesuper(MultiheadAttention, self).__setstate__(state)def forward(self, query, key, value, key_padding_mask=None,need_weights=True, attn_mask=None):# type: (Tensor, Tensor, Tensor, Optional[Tensor], bool, Optional[Tensor]) -> Tuple[Tensor, Optional[Tensor]]r"""Args:query, key, value: map a query and a set of key-value pairs to an output.See "Attention Is All You Need" for more details.key_padding_mask: if provided, specified padding elements in the key willbe ignored by the attention. This is an binary mask. When the value is True,the corresponding value on the attention layer will be filled with -inf.need_weights: output attn_output_weights.attn_mask: mask that prevents attention to certain positions. This is an additive mask(i.e. the values will be added to the attention layer).Shape:- Inputs:- query: :math:`(L, N, E)` where L is the target sequence length, N is the batch size, E isthe embedding dimension.- key: :math:`(S, N, E)`, where S is the source sequence length, N is the batch size, E isthe embedding dimension.- value: :math:`(S, N, E)` where S is the source sequence length, N is the batch size, E isthe embedding dimension.- key_padding_mask: :math:`(N, S)`, ByteTensor, where N is the batch size, S is the source sequence length.- attn_mask: :math:`(L, S)` where L is the target sequence length, S is the source sequence length.- Outputs:- attn_output: :math:`(L, N, E)` where L is the target sequence length, N is the batch size,E is the embedding dimension.- attn_output_weights: :math:`(N, L, S)` where N is the batch size,L is the target sequence length, S is the source sequence length."""if not self._qkv_same_embed_dim:return multi_head_attention_forward(query, key, value, self.embed_dim, self.num_heads,self.in_proj_weight, self.in_proj_bias,self.bias_k, self.bias_v, self.add_zero_attn,self.dropout, self.out_proj.weight, self.out_proj.bias,training=self.training,key_padding_mask=key_padding_mask, need_weights=need_weights,attn_mask=attn_mask, use_separate_proj_weight=True,q_proj_weight=self.q_proj_weight, k_proj_weight=self.k_proj_weight,v_proj_weight=self.v_proj_weight)else:return multi_head_attention_forward(query, key, value, self.embed_dim, self.num_heads,self.in_proj_weight, self.in_proj_bias,self.bias_k, self.bias_v, self.add_zero_attn,self.dropout, self.out_proj.weight, self.out_proj.bias,training=self.training,key_padding_mask=key_padding_mask, need_weights=need_weights,attn_mask=attn_mask)class TransformerEncoderLayer(nn.Module):def __init__(self, d_model, nhead, dim_feedforward=2048, dropout=0, activation="relu"):super(TransformerEncoderLayer, self).__init__()self.self_attn = MultiheadAttention(d_model, nhead, dropout=dropout)# Implementation of Feedforward modelself.linear1 = nn.Linear(d_model, dim_feedforward)self.dropout = nn.Dropout(dropout)self.linear2 = nn.Linear(dim_feedforward, d_model)self.norm1 = nn.LayerNorm(d_model)self.norm2 = nn.LayerNorm(d_model)self.dropout1 = nn.Dropout(dropout)self.dropout2 = nn.Dropout(dropout)self.activation = _get_activation_fn(activation)def forward(self, src, src_mask=None, src_key_padding_mask=None):r"""Pass the input through the encoder layer.Args:src: the sequnce to the encoder layer (required).src_mask: the mask for the src sequence (optional).src_key_padding_mask: the mask for the src keys per batch (optional).Shape:see the docs in Transformer class."""src2, attn = self.self_attn(src, src, src, attn_mask=src_mask,key_padding_mask=src_key_padding_mask)src = src + self.dropout1(src2)src = self.norm1(src)if hasattr(self, "activation"):src2 = self.linear2(self.dropout(self.activation(self.linear1(src))))else: # for backward compatibilitysrc2 = self.linear2(self.dropout(F.relu(self.linear1(src))))src = src + self.dropout2(src2)src = self.norm2(src)return src, attnclass TransformerEncoder(nn.Module):r"""TransformerEncoder is a stack of N encoder layersArgs:encoder_layer: an instance of the TransformerEncoderLayer() class (required).num_layers: the number of sub-encoder-layers in the encoder (required).norm: the layer normalization component (optional).Examples::>>> encoder_layer = nn.TransformerEncoderLayer(d_model=512, nhead=8)>>> transformer_encoder = nn.TransformerEncoder(encoder_layer, num_layers=6)>>> src = torch.rand(10, 32, 512)>>> out = transformer_encoder(src)"""def __init__(self, encoder_layer, num_layers, norm=None):super(TransformerEncoder, self).__init__()self.layers = _get_clones(encoder_layer, num_layers)self.num_layers = num_layersself.norm = normdef forward(self, src, mask=None, src_key_padding_mask=None):r"""Pass the input through the encoder layers in turn.Args:src: the sequnce to the encoder (required).mask: the mask for the src sequence (optional).src_key_padding_mask: the mask for the src keys per batch (optional).Shape:see the docs in Transformer class."""output = srcatts = []for i in range(self.num_layers):output, attn = self.layers[i](output, src_mask=mask,src_key_padding_mask=src_key_padding_mask)atts.append(attn)if self.norm:output = self.norm(output)return outputclass TransformerModel(nn.Module):def __init__(self, ninp, nhead, nhid, nlayers, dropout=0.5):super(TransformerModel, self).__init__()self.model_type = 'Transformer'self.src_mask = Noneencoder_layers = TransformerEncoderLayer(ninp, nhead, nhid, dropout)self.transformer_encoder = TransformerEncoder(encoder_layers, nlayers)self.ninp = ninpdef forward(self, src, mask):n_mask = mask + torch.eye(mask.shape[0], mask.shape[0]).cuda()n_mask = n_mask.float().masked_fill(n_mask == 0., float(-1e20)).masked_fill(n_mask == 1., float(0.0))output = self.transformer_encoder(src, mask=n_mask)return outputclass STAR(torch.nn.Module):def __init__(self, args, dropout_prob=0):super(STAR, self).__init__()# set parameters for network architectureself.embedding_size = [32]self.output_size = 2self.dropout_prob = dropout_probself.args = argsself.temporal_encoder_layer = TransformerEncoderLayer(d_model=32, nhead=8)emsize = 32 # embedding dimensionnhid = 2048 # the dimension of the feedforward network model in TransformerEncodernlayers = 2 # the number of nn.TransformerEncoderLayer in nn.TransformerEncodernhead = 8 # the number of heads in the multihead-attention modelsdropout = 0.1 # the dropout valueself.spatial_encoder_1 = TransformerModel(emsize, nhead, nhid, nlayers, dropout)self.spatial_encoder_2 = TransformerModel(emsize, nhead, nhid, nlayers, dropout)self.temporal_encoder_1 = TransformerEncoder(self.temporal_encoder_layer, 1)self.temporal_encoder_2 = TransformerEncoder(self.temporal_encoder_layer, 1)# Linear layer to map input to embeddingself.input_embedding_layer_temporal = nn.Linear(2, 32)self.input_embedding_layer_spatial = nn.Linear(2, 32)# Linear layer to output and fusionself.output_layer = nn.Linear(48, 2)self.fusion_layer = nn.Linear(64, 32)# ReLU and dropout initself.relu = nn.ReLU()self.dropout_in = nn.Dropout(self.dropout_prob)self.dropout_in2 = nn.Dropout(self.dropout_prob)def get_st_ed(self, batch_num):""":param batch_num: contains number of pedestrians in different scenes for a batch:type batch_num: list:return: st_ed: list of tuple contains start index and end index of pedestrians in different scenes:rtype: list"""cumsum = torch.cumsum(batch_num, dim=0)st_ed = []for idx in range(1, cumsum.shape[0]):st_ed.append((int(cumsum[idx - 1]), int(cumsum[idx])))st_ed.insert(0, (0, int(cumsum[0])))return st_eddef get_node_index(self, seq_list):""":param seq_list: mask indicates whether pedestrain exists:type seq_list: numpy array [F, N], F: number of frames. N: Number of pedestrians (a mask to indicate whetherthe pedestrian exists):return: All the pedestrians who exist from the beginning to current frame:rtype: numpy array"""for idx, framenum in enumerate(seq_list):if idx == 0:node_indices = framenum > 0else:node_indices *= (framenum > 0)return node_indicesdef update_batch_pednum(self, batch_pednum, ped_list):""":param batch_pednum: batch_num: contains number of pedestrians in different scenes for a batch:type list:param ped_list: mask indicates whether the pedestrian exists through the time window to current frame:type tensor:return: batch_pednum: contains number of pedestrians in different scenes for a batch after removing pedestrian who disappeared:rtype: list"""updated_batch_pednum_ = copy.deepcopy(batch_pednum).cpu().numpy()updated_batch_pednum = copy.deepcopy(batch_pednum)cumsum = np.cumsum(updated_batch_pednum_)new_ped = copy.deepcopy(ped_list).cpu().numpy()for idx, num in enumerate(cumsum):num = int(num)if idx == 0:updated_batch_pednum[idx] = len(np.where(new_ped[0:num] == 1)[0])else:updated_batch_pednum[idx] = len(np.where(new_ped[int(cumsum[idx - 1]):num] == 1)[0])return updated_batch_pednumdef mean_normalize_abs_input(self, node_abs, st_ed):""":param node_abs: Absolute coordinates of pedestrians:type Tensor:param st_ed: list of tuple indicates the indices of pedestrians belonging to the same scene:type List of tupule:return: node_abs: Normalized absolute coordinates of pedestrians:rtype: Tensor"""node_abs = node_abs.permute(1, 0, 2)for st, ed in st_ed:mean_x = torch.mean(node_abs[st:ed, :, 0])mean_y = torch.mean(node_abs[st:ed, :, 1])node_abs[st:ed, :, 0] = (node_abs[st:ed, :, 0] - mean_x)node_abs[st:ed, :, 1] = (node_abs[st:ed, :, 1] - mean_y)return node_abs.permute(1, 0, 2)def forward(self, inputs, iftest=False):nodes_abs, nodes_norm, shift_value, seq_list, nei_lists, nei_num, batch_pednum = inputsnum_Ped = nodes_norm.shape[1]outputs = torch.zeros(nodes_norm.shape[0], num_Ped, 2).cuda()GM = torch.zeros(nodes_norm.shape[0], num_Ped, 32).cuda()noise = get_noise((1, 16), 'gaussian')for framenum in range(self.args.seq_length - 1):if framenum >= self.args.obs_length and iftest:node_index = self.get_node_index(seq_list[:self.args.obs_length])updated_batch_pednum = self.update_batch_pednum(batch_pednum, node_index)st_ed = self.get_st_ed(updated_batch_pednum)nodes_current = outputs[self.args.obs_length - 1:framenum, node_index]nodes_current = torch.cat((nodes_norm[:self.args.obs_length, node_index], nodes_current))node_abs_base = nodes_abs[:self.args.obs_length, node_index]node_abs_pred = shift_value[self.args.obs_length:framenum + 1, node_index] + outputs[self.args.obs_length - 1:framenum,node_index]node_abs = torch.cat((node_abs_base, node_abs_pred), dim=0)# We normalize the absolute coordinates using the mean value in the same scenenode_abs = self.mean_normalize_abs_input(node_abs, st_ed)else:node_index = self.get_node_index(seq_list[:framenum + 1])nei_list = nei_lists[framenum, node_index, :]nei_list = nei_list[:, node_index]updated_batch_pednum = self.update_batch_pednum(batch_pednum, node_index)st_ed = self.get_st_ed(updated_batch_pednum)nodes_current = nodes_norm[:framenum + 1, node_index]# We normalize the absolute coordinates using the mean value in the same scenenode_abs = self.mean_normalize_abs_input(nodes_abs[:framenum + 1, node_index], st_ed)# Input Embeddingif framenum == 0:temporal_input_embedded = self.dropout_in(self.relu(self.input_embedding_layer_temporal(nodes_current)))else:temporal_input_embedded = self.dropout_in(self.relu(self.input_embedding_layer_temporal(nodes_current)))temporal_input_embedded[:framenum] = GM[:framenum, node_index]spatial_input_embedded_ = self.dropout_in2(self.relu(self.input_embedding_layer_spatial(node_abs)))spatial_input_embedded = self.spatial_encoder_1(spatial_input_embedded_[-1].unsqueeze(1), nei_list)spatial_input_embedded = spatial_input_embedded.permute(1, 0, 2)[-1]temporal_input_embedded_last = self.temporal_encoder_1(temporal_input_embedded)[-1]temporal_input_embedded = temporal_input_embedded[:-1]fusion_feat = torch.cat((temporal_input_embedded_last, spatial_input_embedded), dim=1)fusion_feat = self.fusion_layer(fusion_feat)spatial_input_embedded = self.spatial_encoder_2(fusion_feat.unsqueeze(1), nei_list)spatial_input_embedded = spatial_input_embedded.permute(1, 0, 2)temporal_input_embedded = torch.cat((temporal_input_embedded, spatial_input_embedded), dim=0)temporal_input_embedded = self.temporal_encoder_2(temporal_input_embedded)[-1]noise_to_cat = noise.repeat(temporal_input_embedded.shape[0], 1)temporal_input_embedded_wnoise = torch.cat((temporal_input_embedded, noise_to_cat), dim=1)outputs_current = self.output_layer(temporal_input_embedded_wnoise)outputs[framenum, node_index] = outputs_currentGM[framenum, node_index] = temporal_input_embeddedreturn outputs