Pytorch 數組反轉報錯 ValueError some of the strides of a given numpy array are negative

我在跑以下代碼時出現錯誤

pic = pic[:,:, ::-1,:]
pic = torch.from_numpy(pic.transpose([3,0,1,2]))
## ValueError: some of the strides of a given numpy array are negative

解決方案

pic = pic[:,:, ::-1,:].copy()  #加上.copy() 

具體可參考:discuss.pytorch

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章