Google cloud platform Can';在我的自定义预测器类代码中,似乎没有导入我的Pytorch模型架构类,以便在AI平台上进行自定义管道部署
我在AI平台上部署一个简单的Pytorch训练模型时遇到问题 以下是错误:Google cloud platform Can';在我的自定义预测器类代码中,似乎没有导入我的Pytorch模型架构类,以便在AI平台上进行自定义管道部署,google-cloud-platform,deployment,google-cloud-ml,gcp-ai-platform-notebook,gcp-ai-platform-training,Google Cloud Platform,Deployment,Google Cloud Ml,Gcp Ai Platform Notebook,Gcp Ai Platform Training,我在AI平台上部署一个简单的Pytorch训练模型时遇到问题 以下是错误: Creating version (this might take a few minutes)......failed. ERROR: (gcloud.beta.ai-platform.versions.create) Create Version failed. Bad model detected with error: "Failed to load model: Unexpected error when l
Creating version (this might take a few minutes)......failed.
ERROR: (gcloud.beta.ai-platform.versions.create) Create Version failed. Bad model detected with error: "Failed to load model: Unexpected error when loading the model: Can't get attribute 'Net'
on <module '__main__' from 'prediction_server_beta.py'> (Error code: 0)"
我尝试更改代码并保存模型格式(.pkl、.pth、.pt),但似乎没有任何效果。我还尝试将我的模型类包含在与自定义预测器类相同的.py脚本中,但也没有成功。
pip可安装软件包包含所有必要的代码,即模型代码和自定义预测器代码。
谢谢你的帮助 请看这个:请看这个:
import os
import pickle
import numpy as np
import torch
from torch_model import *
class CustomModelPrediction(object):
def __init__(self, model):
self._model = model
def predict(self, instances):
input = torch.Tensor(instances)
predictions = self._model(input)
return predictions
@classmethod
def from_path(cls, model_dir):
from torch_model import Net
model = Net()
model = torch.load(os.path.join(model_dir, 'pickle_saved_model.pkl'))
#model.eval()
return cls(model)