今天跑程序的過程中,遇到兩個報錯信息,由于不耽誤程序的運行,之前一直沒有留意,今天給修復了一下bug
報錯信息:
UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor). ? y_support=torch.tensor(y_support,dtype=torch.int64)
解決方案:torch.tensor改為:torch.as
#改之前
y_support=torch.tensor(y_support,dtype=torch.int64)
#改之后
y_support=torch.as_tensor(y_support,dtype=torch.int64)
另一個報錯信息:
?UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
報錯原因:
softmax()函數(shù)被棄用,雖然程序還是可以運行成功,但是這個做法不被pytorch所贊成。這個寫法在早期的pytorch版本是沒有警告的,現(xiàn)在因為其他考慮,要加上有指明dim參數(shù)。
解決方案:?nn.Softmax()改為nn.Softmax(dim=1)文章來源:http://www.zghlxwxcb.cn/news/detail-510489.html
注意:dim=某個數(shù)字,這個數(shù)字可以根據(jù)自己的需要進行更改。文章來源地址http://www.zghlxwxcb.cn/news/detail-510489.html
到了這里,關(guān)于UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone...的解決方案的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!