[英]Azure machine learning unable to load pytorch Model from the outputs folder
I am unable to load saved pytorch model from the outputs folder in my other scripts.我无法从其他脚本的输出文件夹中加载已保存的 pytorch model。 I am using following lines of code to save the 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')
and using the following code to access it:并使用以下代码访问它:
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)
but when I run the above mentioned code, I get this error: No such file or directory: './outputs/model/best-model.pth'但是当我运行上面提到的代码时,我得到这个错误:没有这样的文件或目录:'./outputs/model/best-model.pth'
Also I want to know is there a way to get the saved model from Azure Models?另外我想知道有没有办法从 Azure 模型中获取保存的 model? I have tried to get it by using following lines of code:
我试图通过使用以下代码行来获取它:
from azureml.core.model import Model
model = Model(ws, "Pytorch-model")
but it returns Model type object which returns error on model.eval() (error: Model has no such attribute eval()).但它返回 Model 类型 object,它在 model.eval() 上返回错误(错误:Model 没有这样的属性 eval())。
There is no global output folder.没有全局 output 文件夹。 If you want to use a Model in a new script you need to give the script the model as an input or register the model and download the model from the new script.
如果你想在新脚本中使用 Model,你需要给脚本 model 作为输入,或者注册 model 并从新脚本下载 model。
The Model object form from azureml.core.model import Model
is not your pytorch Model. 1 from azureml.core.model import Model
的 Model object 表单不是您的 pytorch Model.1
You can use model.register(...)
to register your model. And model.download(...)
to download you model. Than you can use pytorch to load you model. 2您可以使用
model.register(...)
注册您的 model。使用 model.download model.download(...)
下载您的 model。然后您可以使用 pytorch 加载您的model。2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.