我正在关注本教程VSCODE tensorflow model deployment on Azure。 在这里,我试图部署一个简单的决策树模型来代替tensorflow模型。我创建了一个train.py文件,像这样
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
import pickle
import os
import joblib
data=pd.read_csv('CreditCardWeka.csv')
model=DecisionTreeClassifier()
Y=data['Class']
del data['Class']
X=data
model.fit(X,Y)
os.makedirs('./outputs/model', exist_ok = True)
joblib.dump(model, './outputs/model/dec_model.sav')
此后,我将创建一个计算,创建一个运行配置并选择此文件。此后,我将创建一个实验并运行它并下载输出。我能够下载输出,直到此为止。 之后,我可以成功注册我的模型,并且当我尝试将其部署为“ Azure容器服务”时,它会要求问score.py,这是哪个
import os
import joblib
import json
import time
import sklearn
# Called when the deployed service starts
from azureml.core.model import Model
def init():
global model
# Get the path where the deployed model can be found.
# load models
model_root = Model.get_model_path('decision-tree-model')
model = joblib.load(os.path.join(model_root, 'dec-model.sav'))
# Handle requests to the service
def run(data):
try:
# Pick out the text property of the JSON request.
# This expects a request in the form of {"text": "some text to score for sentiment"}
data = json.loads(data)
prediction = model.predict(data['X'])
#Return prediction
return prediction
except Exception as e:
error = str(e)
return error
它还会要求一个yml文件
name: decision-tree
channels:
- defaults
dependencies:
- python
- sklearn
- joblib
- pip
- pip:
- azureml-defaults
此后,当它开始创建Docker映像时,它将失败,错误是“ Docker映像生成失败”。 我该如何解决?
答案 0 :(得分:0)
在yml文件中,尝试将sklearn更改为scikit-learn。
如果仍然失败,请尝试详细的故障排除说明以获取更多日志:https://docs.microsoft.com/en-us/azure/machine-learning/how-to-troubleshoot-deployment