lstm - 类型错误 : view() takes at most 2 arguments (3 given)

标签 lstm pytorch torch

我尝试在pytorch中使用view(),但我无法输入3个参数。我不知道为什么它一直给出这个错误?谁能帮我这个?

    def forward(self, input):
        lstm_out, self.hidden = self.lstm(input.view(len(input), self.batch_size, -1))

最佳答案

看起来您的输入是一个numpy数组,而不是torch张量。您需要先对其进行转换,例如 input = torch.Tensor(input)

关于lstm - 类型错误 : view() takes at most 2 arguments (3 given),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55805242/

相关文章:

python - Keras 中具有掩蔽支持的均值或最大池化

python - 结合CNN和双向LSTM

pytorch - 固定 torch 的种子random_split()

Pytorch,无法获得 <class 'torch.Tensor' > 的 repr

python - Pytorch中位数 - 这是错误还是我使用错误

torch - 将列向量转置到割炬中

python - 根据 tensorflow 中给定的序列长度数组对 3D 张量进行切片

machine-learning - LSTM 张量形状和超参数 Tensorflow

python - pytorch 数据集中每个类的实例数

lua - Torch/Lua,哪种神经网络结构适合小批量训练?