Tensorflow RuntimeError:索引0处的掩码[1682]的形状与索引0处的索引张量[1,1682]的形状不匹配 我设计了一个堆叠的自动编码器,试图在电影评级中训练我的神经网络,如果用户不评价任何电影,它就不会考虑它
我的训练集运行得很好,但当我运行测试集时,它显示了这个错误 RuntimeError:索引0处的掩码[1682]的形状与索引0处的索引张量[1,1682]的形状不匹配 我在最后的测试块中得到了错误,我在那里进行了评论 代码:-Tensorflow RuntimeError:索引0处的掩码[1682]的形状与索引0处的索引张量[1,1682]的形状不匹配 我设计了一个堆叠的自动编码器,试图在电影评级中训练我的神经网络,如果用户不评价任何电影,它就不会考虑它,tensorflow,pytorch,autoencoder,Tensorflow,Pytorch,Autoencoder,我的训练集运行得很好,但当我运行测试集时,它显示了这个错误 RuntimeError:索引0处的掩码[1682]的形状与索引0处的索引张量[1,1682]的形状不匹配 我在最后的测试块中得到了错误,我在那里进行了评论 代码:- 更改: output[target == 0] = 0 # I get error at this line output[(target == 0).unsqueeze(0)] = 0 至: output[target == 0] = 0 #
更改:
output[target == 0] = 0 # I get error at this line
output[(target == 0).unsqueeze(0)] = 0
至:
output[target == 0] = 0 # I get error at this line
output[(target == 0).unsqueeze(0)] = 0
原因:
output[target == 0] = 0 # I get error at this line
output[(target == 0).unsqueeze(0)] = 0
由target==0
返回的torch.Tensor
的形状为[1682]
(目标==0)。取消查询(0)
将其转换为[11682]
更改:
output[target == 0] = 0 # I get error at this line
output[(target == 0).unsqueeze(0)] = 0
至:
output[target == 0] = 0 # I get error at this line
output[(target == 0).unsqueeze(0)] = 0
原因:
output[target == 0] = 0 # I get error at this line
output[(target == 0).unsqueeze(0)] = 0
由target==0
返回的torch.Tensor
的形状为[1682]
(target==0)。unsqueze(0)
将其转换为[11682]
如果您查看SAE的培训,目标是输入的克隆,它通过.unsqueze(0)函数增加了维度
如果查看SAE的测试,则目标没有添加的维度,因此请按如下所示修改代码
改变
目标=变量(测试集[id\U用户]) 到
目标=变量(测试集[id\U用户])。取消查询(0)
因此,您的目标具有张量所需的多个dim。如果您查看SAE的培训,目标是输入的克隆,通过.unsqueze(0)函数增加了维度 如果查看SAE的测试,则目标没有添加的维度,因此请按如下所示修改代码 改变
目标=变量(测试集[id\U用户]) 到
目标=变量(测试集[id\U用户])。取消查询(0)
因此,你的目标比张量所需的暗度要大