【发布时间】:2021-04-03 04:17:12
【问题描述】:
目标是在神经网络设置中最小化实际向量和预测向量之间的角度。有人可以检查以下执行是否正确?
criterion = nn.CosineSimilarity()
loss = torch.mean(torch.abs(criterion(actual_vectors,predicted_vectors)))
#back-propagation on the above *loss* will try cos(angle) = 0. But I want angle between the vectors to be 0 or cos(angle) = 1.
loss = 1 - loss
#To me, the above does not seem right. Isn't back-propagation on the above 'loss' similar to minimizing the negative of 'loss' from line 2?
#Does '1' have no role to play here when back-propagation is applied?
loss.backward()
【问题讨论】:
标签: python neural-network pytorch conv-neural-network loss-function