简体   繁体   English

Azure 机器学习无法从输出文件夹加载 pytorch Model

[英]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.

相关问题 PyTorch model 新机器第一次加载太多 - PyTorch model take too much to load the first time in a new machine 无法在运行于 Azure 机器学习实验的脚本中的 python 中安装 python-dotenv - unable to install python-dotenv in python in script running on Azure Machine Learning experiment 无法通过 azure 机器学习使用 python 启动/停止计算实例 - Unable to start/stop compute instance through azure machine learning using python 如何使用 az ml cli 获取在 Azure 机器学习服务 Model 注册表中注册的最新版本的 Model ID? - How to get Model ID of the Latest Version registered in Azure Machine Learning Service Model Registry using az ml cli? Azure 机器学习笔记本:ModuleNotFound 错误 - Azure Machine Learning notebooks: ModuleNotFound error 将最新的文件夹从 azure blob 存储加载到 azure 数据工厂 - Load the latest folder from azure blob storage to azure data factory 在 Azure Machine Learning Studio 中注册并获取一个环境,该环境源自自创的 Docker 图像 - Registering and getting an environment in Azure Machine Learning Studio that derives from a self-created Docker image Azure 机器学习是否对计算实例收费,即使它们已停止? - Does Azure Machine Learning charge for Compute Instances even when they are stopped? 如何在推理脚本中给出 azure 机器学习数据集路径? - How give azure machine learning dataset path in an inference script? Azure Devops 服务负责人和 Azure 机器学习工作区 - Azure Devops Service Principal with Azure Machine Learning Workspace
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM