Multidimensional-time-series-with-transformer icon indicating copy to clipboard operation
Multidimensional-time-series-with-transformer copied to clipboard

模型读取报错

Open jiejiangd opened this issue 3 years ago • 4 comments

RuntimeError: The expanded size of the tensor (3) must match the existing size (4) at non-singleton dimension 1. Target sizes: [5000, 3]. Tensor sizes: [5000, 4]

jiejiangd avatar Aug 29 '22 08:08 jiejiangd

不知道问题出在哪里,数据格式跟您的也是一样的,只不过是7维特征,单步输出

jiejiangd avatar Aug 29 '22 08:08 jiejiangd


RuntimeError Traceback (most recent call last) /tmp/ipykernel_20169/760475506.py in 1 train_data, val_data,scaler = get_data() ----> 2 model = TransAm().to(device) 3 4 criterion = nn.MSELoss() 5 lr = 0.005

/tmp/ipykernel_20169/444366459.py in init(self, feature_size, num_layers, dropout) 5 6 self.src_mask = None ----> 7 self.pos_encoder = PositionalEncoding(feature_size) 8 self.encoder_layer = nn.TransformerEncoderLayer(d_model=feature_size, nhead=7, dropout=dropout) 9 self.transformer_encoder = nn.TransformerEncoder(self.encoder_layer, num_layers=num_layers)

/tmp/ipykernel_20169/3101524472.py in init(self, d_model, max_len) 7 div_term = torch.exp(torch.arange(0, d_model, 2).float() * (-math.log(10000.0) / d_model)) 8 pe[:, 0::2] = torch.sin(position * div_term) ----> 9 pe[:, 1::2] = torch.cos(position * div_term) 10 pe = pe.unsqueeze(0).transpose(0, 1) 11 #pe.requires_grad = False

RuntimeError: The expanded size of the tensor (3) must match the existing size (4) at non-singleton dimension 1. Target sizes: [5000, 3]. Tensor sizes: [5000, 4]

jiejiangd avatar Aug 29 '22 08:08 jiejiangd

想问一下特征不能是单数吗

jiejiangd avatar Aug 30 '22 03:08 jiejiangd

想问一下特征不能是单数吗

不能

dongfeicui avatar Sep 13 '22 07:09 dongfeicui

应该是网络结构和输入特征不匹配,建议修改神经网络输入维度大小。如果还有问题,欢迎继续讨论。

RuifMaxx avatar Oct 27 '22 01:10 RuifMaxx