[英]How can I get a view of input as a complex tensor? RuntimeError: Tensor must have a last dimension with stride 1
[英]How can I get the MSE of a tensor across a specific dimension?
我有2張量與.size
的torch.Size([2272, 161])
我想得到它們之間的均方誤差。 不過,我想它沿着每個161個通道,使我的錯誤張量有.size
的torch.Size([161])
我怎樣才能做到這一點?
似乎torch.nn.MSELoss
不允許我指定維度。
對於nn.MSELoss
您可以指定選項reduction='none'
。 然后,這將為您返回兩個張量的每個條目位置的平方誤差。 然后你可以應用torch.sum/torch.mean。
a = torch.randn(2272,161)
b = torch.randn(2272,161)
loss = nn.MSELoss(reduction='none')
loss_result = torch.sum(loss(a,b),dim=0)
我認為沒有一種直接的方法可以在損失的初始化時指定應用均值/總和的維度。 希望有幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.