[英]Azure machine learning unable to load pytorch Model from the outputs folder
我無法從其他腳本的輸出文件夾中加載已保存的 pytorch model。 我正在使用以下代碼行來保存 model:
os.makedirs("./outputs/model", exist_ok=True)
torch.save({
'model_state_dict': copy.deepcopy(model.state_dict()),
'optimizer_state_dict': optimizer.state_dict()
}, './outputs/model/best-model.pth')
new_run.upload_file("outputs/model/best-model.pth", "outputs/model/best-model.pth")
saved_model = new_run.register_model(model_name='pytorch-model', model_path='outputs/model/best-model.pth')
並使用以下代碼訪問它:
global model
best_model_path = 'outputs/model/best-model.pth'
model_checkpoint = torch.load(best_model_path)
model.load_state_dict(model_checkpoint['model_state_dict'], strict = False)
但是當我運行上面提到的代碼時,我得到這個錯誤:沒有這樣的文件或目錄:'./outputs/model/best-model.pth'
另外我想知道有沒有辦法從 Azure 模型中獲取保存的 model? 我試圖通過使用以下代碼行來獲取它:
from azureml.core.model import Model
model = Model(ws, "Pytorch-model")
但它返回 Model 類型 object,它在 model.eval() 上返回錯誤(錯誤:Model 沒有這樣的屬性 eval())。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.