Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow RuntimeError:索引0处的掩码[1682]的形状与索引0处的索引张量[1,1682]的形状不匹配 我设计了一个堆叠的自动编码器,试图在电影评级中训练我的神经网络,如果用户不评价任何电影,它就不会考虑它_Tensorflow_Pytorch_Autoencoder - Fatal编程技术网

Tensorflow 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 #

我的训练集运行得很好,但当我运行测试集时,它显示了这个错误

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      # 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)

因此,你的目标比张量所需的暗度要大