文|Seraph
高版本Pytorch問題
- 運行
test.py
報錯IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
解決:update
函數的參數loss.data[0]
,prec1.data[0]
,prec5.data[0]
等修改爲loss.item()
,prec1.item()
,prec5.item()
。 - 執行
python visualize.py DARTS
報錯:
test failed: ExecutableNotFound: failed to execute ['dot', '-Tpng'],make sure the Graphviz executables are on your systems ' PATH
解決:除了pip install graphviz
,還需要apt install graphviz
FileNotFoundError: [Errno 2] No such file or directory: 'xdg-open'
解決:安裝apt install xdg-utils
- 使用train_search.py得到的weight.pt進行test.py測試報錯:
RuntimeError: Error(s) in loading state_dict for NetworkCIFAR
Missing key(s) in state_dict:
解決:修改utils.py模塊中的load函數如下,(Pytorch老版本兼容問題)
def load(model, model_path):
model.load_state_dict(torch.load(model_path),False)
size mismatch for : copying a param of from checkpoint, where the shape is torch.Size in current model.
解決:輸入運行命令時輸入與.pt
文件中模型一樣的--init_channels 16
和--layers 8
。由於test.py和train.py中這兩個參數的默認值時一樣的,而train_search.py是不一樣的,所以要統一參數值,才能使運行模型一致。