在PyTorch中运行AutoEncoder模型时,我发现了一个奇怪的错误。
我的代码:
model = AutoEncoder(num_items, args.inner_layers, num_items, da=args.num_attention, dropout_rate=args.dropout_rate)
item_vector = self.linear1.weight[:, T.LongTensor(batch_item_index[0].astype(np.int32))]
inner_product = item_vector.t().mm(self.linear4.weight.t())
在看到类似问题中批次索引的原因是-1的解释后,我试图使索引从0开始(https://github.com/jwyang/faster-rcnn.pytorch/issues/311),但没有起作用。
这是我第一次在Stack Overflow上没有遇到类似的问题,我做错了什么?
Traceback (most recent call last):
File "run.py", line 155, in <module>
main()
File "run.py", line 151, in main
train_autoencoder(train_matrix, test_set)
File "run.py", line 86, in train_autoencoder
y_pred = model(batch_item_index, place_correlation)
File "C:Usersuseranaconda3envssaenadlibsite-packagestorchnnmodulesmodule.py", line 491, in __call__
result = self.forward(*input, **kwargs)
File "C:Usersusersaenadmodel.py", line 58, in forward
inner_product = item_vector.t().mm(self.linear4.weight.t())
RuntimeError: invalid argument 1: out of range at c:programdataminiconda3conda-bldpytorch_1524543037166workatensrcthgeneric/THTensor.cpp:454**
我发现item_vector是空张量([[]](!因此,我添加了以下代码来处理item_vector.Size为0时的异常。
if item_vector.shape == torch.Size([0]):
continue
<--它是有效的。
希望这能帮助有同样错误的人。:(